Ignore:
Timestamp:
Nov 30, 2023, 10:16:14 PM (5 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/Database.pas

    r349 r465  
    2626
    2727  nStartUn = 1;
    28   StartUn: array [0 .. nStartUn - 1] of integer = (0); // mix of start units
     28  StartUn: array [0 .. nStartUn - 1] of Integer = (0); // mix of start units
    2929
    3030  CityOwnTile = 13;
     
    5050  Mode: TGameMode;
    5151  GWonder: array [0 .. nWonder - 1] of TWonderInfo;
    52   ServerVersion: array [0 .. nPl - 1] of integer;
    53   ProcessClientData: array [0 .. nPl - 1] of boolean;
     52  ServerVersion: array [0 .. nPl - 1] of Integer;
     53  ProcessClientData: array [0 .. nPl - 1] of Boolean;
    5454  CL: TCmdList;
    5555{$IFDEF TEXTLOG}CmdInfo: string;
     
    5858  // map data
    5959  RealMap: array [0 .. lxmax * lymax - 1] of Cardinal;
    60   Continent: array [0 .. lxmax * lymax - 1] of integer;
     60  Continent: array [0 .. lxmax * lymax - 1] of Integer;
    6161  { continent id for each tile }
    6262  Occupant: array [0 .. lxmax * lymax - 1] of ShortInt;
     
    6565  ObserveLevel: array [0 .. lxmax * lymax - 1] of Cardinal;
    6666  { Observe Level of player p in bits 2*p and 2*p+1 }
    67   UsedByCity: array [0 .. lxmax * lymax - 1] of integer;
     67  UsedByCity: array [0 .. lxmax * lymax - 1] of Integer;
    6868  { location of exploiting city for
    6969    each tile, =-1 if not exploited }
     
    7171  // player data
    7272  RW: array [0 .. nPl - 1] of TPlayerContext; { player data }
    73   Difficulty: array [0 .. nPl - 1] of integer;
     73  Difficulty: array [0 .. nPl - 1] of Integer;
    7474  GShip: array [0 .. nPl - 1] of TShipInfo;
    7575  ResourceMask: array [0 .. nPl - 1] of Cardinal;
    76   Founded: array [0 .. nPl - 1] of integer; { number of cities founded }
    77   TerritoryCount: array [0 .. nPl] of integer;
     76  Founded: array [0 .. nPl - 1] of Integer; { number of cities founded }
     77  TerritoryCount: array [0 .. nPl] of Integer;
    7878  LastValidStat, Researched, Discovered, // number of tiles discovered
    79   GrWallContinent: array [0 .. nPl - 1] of integer;
     79  GrWallContinent: array [0 .. nPl - 1] of Integer;
    8080  RWemix: array [0 .. nPl - 1, 0 .. nPl - 1, 0 .. nmmax - 1] of SmallInt;
    8181  // [p1,p2,mix] -> index of p2's model mix in p1's enemy model list
    8282  Destroyed: array [0 .. nPl - 1, 0 .. nPl - 1, 0 .. nmmax - 1] of SmallInt;
    8383  // [p1,p2,mix] -> number of p2's units with model mix that p1 has destroyed
    84   nTech: array [0 .. nPl - 1] of integer; { number of known techs }
     84  nTech: array [0 .. nPl - 1] of Integer; { number of known techs }
    8585  // NewContact: array[0..nPl-1,0..nPl-1] of boolean;
    8686
    8787type
    88   TVicinity8Loc = array [0 .. 7] of integer;
    89   TVicinity21Loc = array [0 .. 27] of integer;
    90 
    91 procedure MaskD(var x: array of Cardinal; Count, Mask: Cardinal);
    92 procedure IntServer(Command, Player, Subject: integer; var Data);
    93 procedure CompactLists(p: integer);
    94 procedure ClearTestFlags(ClearFlags: integer);
    95 procedure SetTestFlags(p, SetFlags: integer);
     88  TVicinity8Loc = array [0 .. 7] of Integer;
     89  TVicinity21Loc = array [0 .. 27] of Integer;
     90
     91procedure MaskD(var X: array of Cardinal; Count, Mask: Cardinal);
     92procedure IntServer(Command, Player, Subject: Integer; var Data);
     93procedure CompactLists(P: Integer);
     94procedure ClearTestFlags(ClearFlags: Integer);
     95procedure SetTestFlags(P, SetFlags: Integer);
    9696
    9797// Tech Related Functions
    98 function TechBaseCost(nTech, diff: integer): integer;
    99 function TechCost(p: integer): integer;
    100 procedure CalculateModel(var m: TModel);
    101 procedure CheckSpecialModels(p, pre: integer);
    102 procedure EnableDevModel(p: integer);
    103 procedure SeeTech(p, ad: integer);
    104 procedure DiscoverTech(p, ad: integer);
    105 procedure CheckExpiration(Wonder: integer);
     98function TechBaseCost(nTech, diff: Integer): Integer;
     99function TechCost(P: Integer): Integer;
     100procedure CalculateModel(var M: TModel);
     101procedure CheckSpecialModels(P, pre: Integer);
     102procedure EnableDevModel(P: Integer);
     103procedure SeeTech(P, ad: Integer);
     104procedure DiscoverTech(P, ad: Integer);
     105procedure CheckExpiration(Wonder: Integer);
    106106
    107107// Location Navigation
    108 function dLoc(Loc, dx, dy: integer): integer;
    109 procedure dxdy(Loc0, Loc1: integer; var dx, dy: integer);
    110 function Distance(Loc0, Loc1: integer): integer;
    111 procedure V8_to_Loc(Loc0: integer; var VicinityLoc: TVicinity8Loc);
    112 procedure V21_to_Loc(Loc0: integer; var VicinityLoc: TVicinity21Loc);
     108function dLoc(Loc, dx, dy: Integer): Integer;
     109procedure dxdy(Loc0, Loc1: Integer; var dx, dy: Integer);
     110function Distance(Loc0, Loc1: Integer): Integer;
     111procedure V8_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity8Loc);
     112procedure V21_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity21Loc);
    113113
    114114// Game Initialization
    115115procedure InitRandomGame;
    116 procedure InitMapGame(Human: integer);
     116procedure InitMapGame(Human: Integer);
    117117procedure ReleaseGame;
    118118
    119119// Map Editor
    120 function MapGeneratorAvailable: boolean;
     120function MapGeneratorAvailable: Boolean;
    121121procedure CreateElevation;
    122 procedure CreateMap(preview: boolean);
     122procedure CreateMap(preview: Boolean);
    123123procedure InitMapEditor;
    124124procedure ReleaseMapEditor;
    125 procedure EditTile(Loc, NewTile: integer);
     125procedure EditTile(Loc, NewTile: Integer);
    126126
    127127// Map Revealing
    128 function GetTileInfo(p, cix, Loc: integer; var Info: TTileInfo): integer;
    129 procedure Strongest(Loc: integer; var uix, Strength, Bonus, Cnt: integer);
    130 function UnitSpeed(p, mix, Health: integer): integer;
    131 procedure GetUnitReport(p, uix: integer; var UnitReport: TUnitReport);
    132 procedure SearchCity(Loc: integer; var p, cix: integer);
    133 procedure TellAboutModel(p, taOwner, tamix: integer);
    134 function emixSafe(p, taOwner, tamix: integer): integer;
    135 function Discover9(Loc, p, Level: integer;
    136   TellAllied, EnableContact: boolean): boolean;
    137 function Discover21(Loc, p, AdjacentLevel: integer;
    138   TellAllied, EnableContact: boolean): boolean;
    139 procedure DiscoverAll(p, Level: integer);
    140 procedure DiscoverViewAreas(p: integer);
    141 function GetUnitStack(p, Loc: integer): integer;
    142 procedure UpdateUnitMap(Loc: integer; CityChange: boolean = false);
    143 procedure RecalcV8ZoC(p, Loc: integer);
    144 procedure RecalcMapZoC(p: integer);
    145 procedure RecalcPeaceMap(p: integer);
     128function GetTileInfo(P, cix, Loc: Integer; var Info: TTileInfo): Integer;
     129procedure Strongest(Loc: Integer; var uix, Strength, Bonus, Cnt: Integer);
     130function UnitSpeed(P, mix, Health: Integer): Integer;
     131procedure GetUnitReport(P, uix: Integer; var UnitReport: TUnitReport);
     132procedure SearchCity(Loc: Integer; var P, cix: Integer);
     133procedure TellAboutModel(P, taOwner, tamix: Integer);
     134function emixSafe(P, taOwner, tamix: Integer): Integer;
     135function Discover9(Loc, P, Level: Integer;
     136  TellAllied, EnableContact: Boolean): Boolean;
     137function Discover21(Loc, P, AdjacentLevel: Integer;
     138  TellAllied, EnableContact: Boolean): Boolean;
     139procedure DiscoverAll(P, Level: Integer);
     140procedure DiscoverViewAreas(P: Integer);
     141function GetUnitStack(P, Loc: Integer): Integer;
     142procedure UpdateUnitMap(Loc: Integer; CityChange: Boolean = False);
     143procedure RecalcV8ZoC(P, Loc: Integer);
     144procedure RecalcMapZoC(P: Integer);
     145procedure RecalcPeaceMap(P: Integer);
    146146
    147147// Territory Calculation
    148 procedure CheckBorders(OriginLoc: integer; PlayerLosingCity: integer = -1);
    149 procedure LogCheckBorders(p, cix: integer; PlayerLosingCity: integer = -1);
     148procedure CheckBorders(OriginLoc: Integer; PlayerLosingCity: Integer = -1);
     149procedure LogCheckBorders(P, cix: Integer; PlayerLosingCity: Integer = -1);
    150150
    151151// Map Processing
    152 procedure CreateUnit(p, mix: integer);
    153 procedure FreeUnit(p, uix: integer);
    154 procedure PlaceUnit(p, uix: integer);
    155 procedure RemoveUnit(p, uix: integer; Enemy: integer = -1);
    156 procedure RemoveUnit_UpdateMap(p, uix: integer);
    157 procedure RemoveAllUnits(p, Loc: integer; Enemy: integer = -1);
    158 procedure RemoveDomainUnits(d, p, Loc: integer);
    159 procedure FoundCity(p, FoundLoc: integer);
    160 procedure DestroyCity(p, cix: integer; SaveUnits: boolean);
    161 procedure ChangeCityOwner(pOld, cixOld, pNew: integer);
    162 procedure CompleteJob(p, Loc, Job: integer);
     152procedure CreateUnit(P, mix: Integer);
     153procedure FreeUnit(P, uix: Integer);
     154procedure PlaceUnit(P, uix: Integer);
     155procedure RemoveUnit(P, uix: Integer; Enemy: Integer = -1);
     156procedure RemoveUnit_UpdateMap(P, uix: Integer);
     157procedure RemoveAllUnits(P, Loc: Integer; Enemy: Integer = -1);
     158procedure RemoveDomainUnits(D, P, Loc: Integer);
     159procedure FoundCity(P, FoundLoc: Integer);
     160procedure DestroyCity(P, cix: Integer; SaveUnits: Boolean);
     161procedure ChangeCityOwner(pOld, cixOld, pNew: Integer);
     162procedure CompleteJob(P, Loc, Job: Integer);
    163163
    164164// Diplomacy
    165 procedure IntroduceEnemy(p1, p2: integer);
    166 procedure GiveCivilReport(p, pAbout: integer);
    167 procedure GiveMilReport(p, pAbout: integer);
    168 procedure ShowPrice(pSender, pTarget, Price: integer);
    169 function PayPrice(pSender, pTarget, Price: integer; execute: boolean): boolean;
    170 procedure CancelTreaty(p, pWith: integer; DecreaseCredibility: boolean = true);
    171 function DoSpyMission(p, pCity, cix, Mission: integer): Cardinal;
     165procedure IntroduceEnemy(p1, p2: Integer);
     166procedure GiveCivilReport(P, pAbout: Integer);
     167procedure GiveMilReport(P, pAbout: Integer);
     168procedure ShowPrice(pSender, pTarget, Price: Integer);
     169function PayPrice(pSender, pTarget, Price: Integer; execute: Boolean): Boolean;
     170procedure CancelTreaty(P, pWith: Integer; DecreaseCredibility: Boolean = True);
     171function DoSpyMission(P, pCity, cix, Mission: Integer): Cardinal;
     172
    172173
    173174implementation
     
    179180
    180181var
    181   UnBuilt: array [0 .. nPl - 1] of integer; { number of units built }
    182 
    183 procedure MaskD(var x: array of Cardinal; Count, Mask: Cardinal);
     182  UnBuilt: array [0 .. nPl - 1] of Integer; { number of units built }
     183
     184procedure MaskD(var X: array of Cardinal; Count, Mask: Cardinal);
    184185var
    185186  I: Integer;
    186187begin
    187188  for I := 0 to Count - 1 do
    188     x[I] := x[I] and Mask;
    189 end;
    190 
    191 procedure CompactLists(p: integer);
    192 var
    193   uix, uix1, cix: integer;
    194 {$IFOPT O-}V21: integer;
     189    X[I] := X[I] and Mask;
     190end;
     191
     192procedure CompactLists(P: Integer);
     193var
     194  uix, uix1, cix: Integer;
     195{$IFOPT O-}V21: Integer;
    195196  Radius: TVicinity21Loc; {$ENDIF}
    196197begin
    197   with RW[p] do
     198  with RW[P] do
    198199  begin
    199200    // compact unit list
     
    202203      if Un[uix].Loc < 0 then
    203204      begin
    204         dec(nUn);
     205        Dec(nUn);
    205206        Un[uix] := Un[nUn]; { replace removed unit by last }
    206207        if (Un[uix].TroopLoad > 0) or (Un[uix].AirLoad > 0) then
     
    211212      end
    212213      else
    213         inc(uix);
     214        Inc(uix);
    214215
    215216    // compact city list
     
    218219      if City[cix].Loc < 0 then
    219220      begin
    220         dec(nCity);
     221        Dec(nCity);
    221222        City[cix] := City[nCity]; { replace city by last }
    222223        for uix1 := 0 to nUn - 1 do
     
    226227      end
    227228      else
    228         inc(cix);
     229        Inc(cix);
    229230
    230231    // compact enemy city list
     
    233234      if EnemyCity[cix].Loc < 0 then
    234235      begin
    235         dec(nEnemyCity);
     236        Dec(nEnemyCity);
    236237        EnemyCity[cix] := EnemyCity[nEnemyCity]; { replace city by last }
    237238      end
    238239      else
    239         inc(cix);
     240        Inc(cix);
    240241
    241242{$IFOPT O-}
     
    246247        for V21 := 1 to 26 do
    247248          if Tiles and (1 shl V21) <> 0 then
    248             assert(UsedByCity[Radius[V21]] = Loc);
    249       end
     249            Assert(UsedByCity[Radius[V21]] = Loc);
     250      end;
    250251{$ENDIF}
    251252  end;
    252 end; // CompactLists
     253end;
    253254
    254255{
     
    256257  ____________________________________________________________________
    257258}
    258 function TechBaseCost(nTech, diff: integer): integer;
    259 var
    260   c0: single;
     259function TechBaseCost(nTech, diff: Integer): Integer;
     260var
     261  c0: Single;
    261262begin
    262263  c0 := TechFormula_M[diff] * (nTech + 4) *
    263264    exp((nTech + 4) / TechFormula_D[diff]);
    264265  if c0 >= $10000000 then
    265     result := $10000000
     266    Result := $10000000
    266267  else
    267     result := trunc(c0)
    268 end;
    269 
    270 function TechCost(p: integer): integer;
    271 begin
    272   with RW[p] do
    273   begin
    274     result := TechBaseCost(nTech[p], Difficulty[p]);
     268    Result := trunc(c0);
     269end;
     270
     271function TechCost(P: Integer): Integer;
     272begin
     273  with RW[P] do
     274  begin
     275    Result := TechBaseCost(nTech[P], Difficulty[P]);
    275276    if ResearchTech >= 0 then
    276277      if (ResearchTech = adMilitary) or (Tech[ResearchTech] = tsSeen) then
    277         result := result shr 1
     278        Result := Result shr 1
    278279      else if ResearchTech in FutureTech then
    279280        if Government = gFuture then
    280           result := result * 2
     281          Result := Result * 2
    281282        else
    282           result := result * 4;
    283   end
    284 end;
    285 
    286 procedure SetModelFlags(var m: TModel);
    287 begin
    288   m.Flags := 0;
    289   if (m.Domain = dGround) and (m.Kind <> mkDiplomat) then
    290     m.Flags := m.Flags or mdZOC;
    291   if (m.Kind = mkDiplomat) or (m.Attack + m.Cap[mcBombs] = 0) then
    292     m.Flags := m.Flags or mdCivil;
    293   if (m.Cap[mcOver] > 0) or (m.Domain = dSea) and (m.Weight >= 6) then
    294     m.Flags := m.Flags or mdDoubleSupport;
    295 end;
    296 
    297 procedure CalculateModel(var m: TModel);
     283          Result := Result * 4;
     284  end;
     285end;
     286
     287procedure SetModelFlags(var M: TModel);
     288begin
     289  M.Flags := 0;
     290  if (M.Domain = dGround) and (M.Kind <> mkDiplomat) then
     291    M.Flags := M.Flags or mdZOC;
     292  if (M.Kind = mkDiplomat) or (M.Attack + M.Cap[mcBombs] = 0) then
     293    M.Flags := M.Flags or mdCivil;
     294  if (M.Cap[mcOver] > 0) or (M.Domain = dSea) and (M.Weight >= 6) then
     295    M.Flags := M.Flags or mdDoubleSupport;
     296end;
     297
     298procedure CalculateModel(var M: TModel);
    298299{ calculate attack, defense, cost... of a model by features }
    299300var
    300   i: integer;
    301 begin
    302   with m do
     301  I: Integer;
     302begin
     303  with M do
    303304  begin
    304305    Attack := (Cap[mcOffense] + Cap[mcOver]) * MStrength;
     
    311312          Speed := 350 + 200 * Cap[mcNP] + 200 * Cap[mcTurbines];
    312313          if Cap[mcNP] = 0 then
    313             inc(Speed, 100 * Cap[mcSE]);
     314            Inc(Speed, 100 * Cap[mcSE]);
    314315        end;
    315316      dAir:
     
    317318    end;
    318319    Cost := 0;
    319     for i := 0 to nFeature - 1 do
    320       if 1 shl Domain and Feature[i].Domains <> 0 then
    321         inc(Cost, Cap[i] * Feature[i].Cost);
     320    for I := 0 to nFeature - 1 do
     321      if 1 shl Domain and Feature[I].Domains <> 0 then
     322        Inc(Cost, Cap[I] * Feature[I].Cost);
    322323    Cost := Cost * MCost;
    323324    Weight := 0;
    324     for i := 0 to nFeature - 1 do
    325       if 1 shl Domain and Feature[i].Domains <> 0 then
    326         if (Domain = dGround) and (i = mcDefense) then
    327           inc(Weight, Cap[i] * 2)
     325    for I := 0 to nFeature - 1 do
     326      if 1 shl Domain and Feature[I].Domains <> 0 then
     327        if (Domain = dGround) and (I = mcDefense) then
     328          Inc(Weight, Cap[I] * 2)
    328329        else
    329           inc(Weight, Cap[i] * Feature[i].Weight);
    330   end;
    331   SetModelFlags(m);
    332 end;
    333 
    334 procedure CheckSpecialModels(p, pre: integer);
    335 var
    336   i, mix1: integer;
    337   HasAlready: boolean;
    338 begin
    339   for i := 0 to nSpecialModel -
     330          Inc(Weight, Cap[I] * Feature[I].Weight);
     331  end;
     332  SetModelFlags(M);
     333end;
     334
     335procedure CheckSpecialModels(P, pre: Integer);
     336var
     337  I, mix1: Integer;
     338  HasAlready: Boolean;
     339begin
     340  for I := 0 to nSpecialModel -
    340341    1 do { check whether new special model available }
    341     if (SpecialModelPreq[i] = pre) and (RW[p].nModel < nmmax) then
    342     begin
    343       HasAlready := false;
    344       for mix1 := 0 to RW[p].nModel - 1 do
    345         if (RW[p].Model[mix1].Kind = SpecialModel[i].Kind) and
    346           (RW[p].Model[mix1].Attack = SpecialModel[i].Attack) and
    347           (RW[p].Model[mix1].Speed = SpecialModel[i].Speed) then
    348           HasAlready := true;
     342    if (SpecialModelPreq[I] = pre) and (RW[P].nModel < nmmax) then
     343    begin
     344      HasAlready := False;
     345      for mix1 := 0 to RW[P].nModel - 1 do
     346        if (RW[P].Model[mix1].Kind = SpecialModel[I].Kind) and
     347          (RW[P].Model[mix1].Attack = SpecialModel[I].Attack) and
     348          (RW[P].Model[mix1].Speed = SpecialModel[I].Speed) then
     349          HasAlready := True;
    349350      if not HasAlready then
    350351      begin
    351         RW[p].Model[RW[p].nModel] := SpecialModel[i];
    352         SetModelFlags(RW[p].Model[RW[p].nModel]);
    353         with RW[p].Model[RW[p].nModel] do
     352        RW[P].Model[RW[P].nModel] := SpecialModel[I];
     353        SetModelFlags(RW[P].Model[RW[P].nModel]);
     354        with RW[P].Model[RW[P].nModel] do
    354355        begin
    355356          Status := 0;
     
    358359          Built := 0;
    359360          Lost := 0;
    360           ID := p shl 12 + RW[p].nModel;
    361           if (Kind = mkSpecial_Boat) and (ServerVersion[p] < $000EF0) then
     361          ID := P shl 12 + RW[P].nModel;
     362          if (Kind = mkSpecial_Boat) and (ServerVersion[P] < $000EF0) then
    362363            Speed := 350; // old longboat
    363364        end;
    364         inc(RW[p].nModel);
    365       end
    366     end;
    367 end;
    368 
    369 procedure EnableDevModel(p: integer);
    370 begin
    371   with RW[p] do
     365        Inc(RW[P].nModel);
     366      end;
     367    end;
     368end;
     369
     370procedure EnableDevModel(P: Integer);
     371begin
     372  with RW[P] do
    372373    if nModel < nmmax then
    373374    begin
     
    380381        Built := 0;
    381382        Lost := 0;
    382         ID := p shl 12 + nModel
    383       end;
    384       inc(nModel);
    385       inc(Researched[p])
    386     end
    387 end;
    388 
    389 procedure SeeTech(p, ad: integer);
    390 begin
    391 {$IFDEF TEXTLOG}CmdInfo := CmdInfo + Format(' P%d:A%d', [p, ad]); {$ENDIF}
    392   RW[p].Tech[ad] := tsSeen;
     383        ID := P shl 12 + nModel;
     384      end;
     385      Inc(nModel);
     386      Inc(Researched[P]);
     387    end;
     388end;
     389
     390procedure SeeTech(P, ad: Integer);
     391begin
     392{$IFDEF TEXTLOG}CmdInfo := CmdInfo + Format(' P%d:A%d', [P, ad]); {$ENDIF}
     393  RW[P].Tech[ad] := tsSeen;
    393394  // inc(nTech[p]);
    394   inc(Researched[p])
     395  Inc(Researched[P]);
    395396end;
    396397
    397398procedure FreeSlaves;
    398399var
    399   p1, uix: integer;
     400  p1, uix: Integer;
    400401begin
    401402  for p1 := 0 to nPl - 1 do
     
    403404      for uix := 0 to RW[p1].nUn - 1 do
    404405        if RW[p1].Model[RW[p1].Un[uix].mix].Kind = mkSlaves then
    405           RW[p1].Un[uix].Job := jNone
    406 end;
    407 
    408 procedure DiscoverTech(p, ad: integer);
    409 
    410   procedure TellAboutKeyTech(p, Source: integer);
     406          RW[p1].Un[uix].Job := jNone;
     407end;
     408
     409procedure DiscoverTech(P, ad: Integer);
     410
     411  procedure TellAboutKeyTech(P, Source: Integer);
    411412  var
    412     i, p1: integer;
    413   begin
    414     for i := 1 to 3 do
    415       if ad = AgePreq[i] then
     413    I, p1: Integer;
     414  begin
     415    for I := 1 to 3 do
     416      if ad = AgePreq[I] then
    416417        for p1 := 0 to nPl - 1 do
    417           if (p1 <> p) and ((GAlive or GWatching) and (1 shl p1) <> 0) then
    418             RW[p1].EnemyReport[p].Tech[ad] := Source;
    419   end;
    420 
    421 var
    422   i: integer;
     418          if (p1 <> P) and ((GAlive or GWatching) and (1 shl p1) <> 0) then
     419            RW[p1].EnemyReport[P].Tech[ad] := Source;
     420  end;
     421
     422var
     423  I: Integer;
    423424begin
    424425  if ad in FutureTech then
    425426  begin
    426     if RW[p].Tech[ad] < tsApplicable then
    427       RW[p].Tech[ad] := 1
     427    if RW[P].Tech[ad] < tsApplicable then
     428      RW[P].Tech[ad] := 1
    428429    else
    429       inc(RW[p].Tech[ad]);
     430      Inc(RW[P].Tech[ad]);
    430431    if ad <> futResearchTechnology then
    431       inc(nTech[p], 2);
    432     inc(Researched[p], 8);
    433     exit;
    434   end;
    435 
    436   if RW[p].Tech[ad] = tsSeen then
    437   begin
    438     inc(nTech[p]);
    439     inc(Researched[p]);
     432      Inc(nTech[P], 2);
     433    Inc(Researched[P], 8);
     434    Exit;
     435  end;
     436
     437  if RW[P].Tech[ad] = tsSeen then
     438  begin
     439    Inc(nTech[P]);
     440    Inc(Researched[P]);
    440441  end
    441442  else
    442443  begin
    443     inc(nTech[p], 2);
    444     inc(Researched[p], 2);
    445   end;
    446   RW[p].Tech[ad] := tsResearched;
    447   TellAboutKeyTech(p, tsResearched);
    448   CheckSpecialModels(p, ad);
     444    Inc(nTech[P], 2);
     445    Inc(Researched[P], 2);
     446  end;
     447  RW[P].Tech[ad] := tsResearched;
     448  TellAboutKeyTech(P, tsResearched);
     449  CheckSpecialModels(P, ad);
    449450  if ad = adScience then
    450     ResourceMask[p] := ResourceMask[p] or fSpecial2;
     451    ResourceMask[P] := ResourceMask[P] or fSpecial2;
    451452  if ad = adMassProduction then
    452     ResourceMask[p] := ResourceMask[p] or fModern;
    453 
    454   for i := 0 to nWonder - 1 do { check whether wonders expired }
    455     if (GWonder[i].EffectiveOwner <> GWonder[woEiffel].EffectiveOwner) and
    456       (Imp[i].Expiration = ad) then
    457     begin
    458       GWonder[i].EffectiveOwner := -1;
    459       if i = woPyramids then
     453    ResourceMask[P] := ResourceMask[P] or fModern;
     454
     455  for I := 0 to nWonder - 1 do { check whether wonders expired }
     456    if (GWonder[I].EffectiveOwner <> GWonder[woEiffel].EffectiveOwner) and
     457      (Imp[I].Expiration = ad) then
     458    begin
     459      GWonder[I].EffectiveOwner := -1;
     460      if I = woPyramids then
    460461        FreeSlaves;
    461462    end;
    462463end;
    463464
    464 procedure CheckExpiration(Wonder: integer);
     465procedure CheckExpiration(Wonder: Integer);
    465466// GWonder[Wonder].EffectiveOwner must be set before!
    466467var
    467   p: integer;
     468  P: Integer;
    468469begin
    469470  if (Imp[Wonder].Expiration >= 0) and
    470471    (GWonder[woEiffel].EffectiveOwner <> GWonder[Wonder].EffectiveOwner) then
    471     for p := 0 to nPl - 1 do // check if already expired
    472       if (1 shl p and GAlive <> 0) and
    473         (RW[p].Tech[Imp[Wonder].Expiration] >= tsApplicable) then
     472    for P := 0 to nPl - 1 do // check if already expired
     473      if (1 shl P and GAlive <> 0) and
     474        (RW[P].Tech[Imp[Wonder].Expiration] >= tsApplicable) then
    474475      begin
    475476        GWonder[Wonder].EffectiveOwner := -1;
    476477        if Wonder = woPyramids then
    477           FreeSlaves
    478       end
     478          FreeSlaves;
     479      end;
    479480end;
    480481
     
    483484  ____________________________________________________________________
    484485}
    485 function dLoc(Loc, dx, dy: integer): integer;
     486function dLoc(Loc, dx, dy: Integer): Integer;
    486487{ relative location, dx in hor and dy in ver direction from Loc }
    487488var
    488   y0: integer;
     489  y0: Integer;
    489490begin
    490491  if not (Loc >= 0) and (Loc < MapSize) and (dx + lx >= 0) then
    491492    raise Exception.Create('Relative location error');
    492   assert((Loc >= 0) and (Loc < MapSize) and (dx + lx >= 0));
     493  Assert((Loc >= 0) and (Loc < MapSize) and (dx + lx >= 0));
    493494  y0 := Loc div lx;
    494   result := (Loc + (dx + y0 and 1 + lx + lx) shr 1) mod lx + lx * (y0 + dy);
    495   if (result < 0) or (result >= MapSize) then
    496     result := -1;
    497 end;
    498 
    499 procedure dxdy(Loc0, Loc1: integer; var dx, dy: integer);
     495  Result := (Loc + (dx + y0 and 1 + lx + lx) shr 1) mod lx + lx * (y0 + dy);
     496  if (Result < 0) or (Result >= MapSize) then
     497    Result := -1;
     498end;
     499
     500procedure dxdy(Loc0, Loc1: Integer; var dx, dy: Integer);
    500501begin
    501502  dx := ((Loc1 mod lx * 2 + Loc1 div lx and 1) -
     
    504505end;
    505506
    506 function Distance(Loc0, Loc1: integer): integer;
    507 var
    508   dx, dy: integer;
     507function Distance(Loc0, Loc1: Integer): Integer;
     508var
     509  dx, dy: Integer;
    509510begin
    510511  dxdy(Loc0, Loc1, dx, dy);
    511512  dx := abs(dx);
    512513  dy := abs(dy);
    513   result := dx + dy + abs(dx - dy) shr 1;
    514 end;
    515 
    516 procedure V8_to_Loc(Loc0: integer; var VicinityLoc: TVicinity8Loc);
    517 var
    518   x0, y0, lx0: integer;
     514  Result := dx + dy + abs(dx - dy) shr 1;
     515end;
     516
     517procedure V8_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity8Loc);
     518var
     519  x0, y0, lx0: Integer;
    519520begin
    520521  lx0 := lx; // put in register!
     
    526527  VicinityLoc[5] := Loc0 - lx0 * 2;
    527528  VicinityLoc[7] := Loc0 + 1;
    528   inc(Loc0, y0);
     529  Inc(Loc0, y0);
    529530  VicinityLoc[0] := Loc0 + lx0;
    530531  VicinityLoc[2] := Loc0 + lx0 - 1;
     
    537538    if x0 = 0 then
    538539    begin
    539       inc(VicinityLoc[3], lx0);
     540      Inc(VicinityLoc[3], lx0);
    540541      if y0 = 0 then
    541542      begin
    542         inc(VicinityLoc[2], lx0);
    543         inc(VicinityLoc[4], lx0);
    544       end
    545     end
     543        Inc(VicinityLoc[2], lx0);
     544        Inc(VicinityLoc[4], lx0);
     545      end;
     546    end;
    546547  end
    547548  else
    548549  begin
    549     dec(VicinityLoc[7], lx0);
     550    Dec(VicinityLoc[7], lx0);
    550551    if y0 = 1 then
    551552    begin
    552       dec(VicinityLoc[0], lx0);
    553       dec(VicinityLoc[6], lx0);
    554     end
    555   end;
    556 end;
    557 
    558 procedure V21_to_Loc(Loc0: integer; var VicinityLoc: TVicinity21Loc);
    559 var
    560   dx, dy, bit, y0, xComp, yComp, xComp0, xCompSwitch: integer;
    561   dst: ^integer;
     553      Dec(VicinityLoc[0], lx0);
     554      Dec(VicinityLoc[6], lx0);
     555    end;
     556  end;
     557end;
     558
     559procedure V21_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity21Loc);
     560var
     561  dx, dy, bit, y0, xComp, yComp, xComp0, xCompSwitch: Integer;
     562  dst: ^Integer;
    562563begin
    563564  y0 := Loc0 div lx;
     
    565566  xCompSwitch := xComp0 - 1 + y0 and 1;
    566567  if xComp0 < 0 then
    567     inc(xComp0, lx);
     568    Inc(xComp0, lx);
    568569  if xCompSwitch < 0 then
    569     inc(xCompSwitch, lx);
     570    Inc(xCompSwitch, lx);
    570571  xCompSwitch := xCompSwitch xor xComp0;
    571572  yComp := lx * (y0 - 3);
     
    582583      else
    583584        dst^ := -1;
    584       inc(xComp);
     585      Inc(xComp);
    585586      if xComp >= lx then
    586         dec(xComp, lx);
    587       inc(dst);
     587        Dec(xComp, lx);
     588      Inc(dst);
    588589      bit := bit shl 1;
    589590    end;
    590     inc(yComp, lx);
     591    Inc(yComp, lx);
    591592  end;
    592593end;
     
    597598}
    598599var
    599   primitive: integer;
    600   StartLoc, StartLoc2: array [0 .. nPl - 1] of integer; { starting coordinates }
     600  primitive: Integer;
     601  StartLoc, StartLoc2: array [0 .. nPl - 1] of Integer; { starting coordinates }
    601602  Elevation: array [0 .. lxmax * lymax - 1] of Byte; { map elevation }
    602   ElCount: array [Byte] of integer; { count of elevation occurance }
     603  ElCount: array [Byte] of Integer; { count of elevation occurance }
    603604
    604605procedure CalculatePrimitive;
    605606var
    606   i, j: integer;
     607  I, J: Integer;
    607608begin
    608609  primitive := 1;
    609   i := 2;
    610   while i * i <= MapSize + 1 do // test whether prime
    611   begin
    612     if (MapSize + 1) mod i = 0 then
     610  I := 2;
     611  while I * I <= MapSize + 1 do // test whether prime
     612  begin
     613    if (MapSize + 1) mod I = 0 then
    613614      primitive := 0;
    614     inc(i)
     615    Inc(I);
    615616  end;
    616617
    617618  if primitive > 0 then
    618619    repeat
    619       inc(primitive);
    620       i := 1;
    621       j := 0;
     620      Inc(primitive);
     621      I := 1;
     622      J := 0;
    622623      repeat
    623         inc(j);
    624         i := i * primitive mod (MapSize + 1)
    625       until (i = 1) or (j = MapSize + 1);
    626     until j = MapSize;
    627 end;
    628 
    629 function MapGeneratorAvailable: boolean;
    630 begin
    631   result := (primitive > 0) and (lx >= 20) and (ly >= 40)
     624        Inc(J);
     625        I := I * primitive mod (MapSize + 1);
     626      until (I = 1) or (J = MapSize + 1);
     627    until J = MapSize;
     628end;
     629
     630function MapGeneratorAvailable: Boolean;
     631begin
     632  Result := (primitive > 0) and (lx >= 20) and (ly >= 40);
    632633end;
    633634
    634635procedure CreateElevation;
    635636const
    636   d = 64;
     637  D = 64;
    637638  Smooth = 0.049; { causes low amplitude of short waves }
    638639  Detail = 0.095; { causes short period of short waves }
     
    641642
    642643var
    643   sa, ca, f1, f2: array [1 .. d] of single;
    644   imerge, x, y: integer;
    645   v, maxv: single;
    646 
    647   function Value(x, y: integer): single; { elevation formula }
     644  sa, ca, f1, f2: array [1 .. D] of Single;
     645  imerge, X, Y: Integer;
     646  V, maxv: Single;
     647
     648  function Value(X, Y: Integer): Single; { elevation formula }
    648649  var
    649     i: integer;
    650   begin
    651     result := 0;
    652     for i := 1 to d do
    653       result := result + sin(f1[i] * ((x * 2 + y and 1) * sa[i] + y * 1.5 *
    654         ca[i])) * f2[i];
     650    I: Integer;
     651  begin
     652    Result := 0;
     653    for I := 1 to D do
     654      Result := Result + sin(f1[I] * ((X * 2 + Y and 1) * sa[I] + Y * 1.5 *
     655        ca[I])) * f2[I];
    655656    { x values effectively multiplied with 2 to get 2 horizantal periods
    656657      of the prime waves }
     
    658659
    659660begin
    660   for x := 1 to d do { prepare formula parameters }
    661   begin
    662 {$IFNDEF SCR} if x = 1 then
    663       v := pi / 2 { first wave goes horizontal }
    664     else {$ENDIF} v := DelphiRandom * 2 * pi;
    665     sa[x] := sin(v) / lx;
    666     ca[x] := cos(v) / ly;
    667     f1[x] := 2 * pi * exp(Detail * (x - 1));
    668     f2[x] := exp(-x * Smooth)
     661  for X := 1 to D do { prepare formula parameters }
     662  begin
     663{$IFNDEF SCR} if X = 1 then
     664      V := pi / 2 { first wave goes horizontal }
     665    else {$ENDIF} V := DelphiRandom * 2 * pi;
     666    sa[X] := sin(V) / lx;
     667    ca[X] := cos(V) / ly;
     668    f1[X] := 2 * pi * exp(Detail * (X - 1));
     669    f2[X] := exp(-X * Smooth);
    669670  end;
    670671
     
    672673  FillChar(ElCount, SizeOf(ElCount), 0);
    673674  maxv := 0;
    674   for x := 0 to lx - 1 do
    675     for y := 0 to ly - 1 do
    676     begin
    677       v := Value(x, y);
    678       if x * 2 < imerge then
    679         v := (x * 2 * v + (imerge - x * 2) * Value(x + lx, y)) / imerge;
    680       v := v - sqr(sqr(2 * y / ly - 1)); { soft cut at poles }
    681       if v > maxv then
    682         maxv := v;
    683 
    684       if v < -4 then
    685         Elevation[x + lx * y] := 0
    686       else if v > 8.75 then
    687         Elevation[x + lx * y] := 255
     675  for X := 0 to lx - 1 do
     676    for Y := 0 to ly - 1 do
     677    begin
     678      V := Value(X, Y);
     679      if X * 2 < imerge then
     680        V := (X * 2 * V + (imerge - X * 2) * Value(X + lx, Y)) / imerge;
     681      V := V - sqr(sqr(2 * Y / ly - 1)); { soft cut at poles }
     682      if V > maxv then
     683        maxv := V;
     684
     685      if V < -4 then
     686        Elevation[X + lx * Y] := 0
     687      else if V > 8.75 then
     688        Elevation[X + lx * Y] := 255
    688689      else
    689         Elevation[x + lx * y] := Round((v + 4) * 20);
    690       inc(ElCount[Elevation[x + lx * y]])
     690        Elevation[X + lx * Y] := Round((V + 4) * 20);
     691      Inc(ElCount[Elevation[X + lx * Y]]);
    691692    end;
    692693end;
     
    694695procedure FindContinents;
    695696
    696   procedure ReplaceCont(a, b, Stop: integer);
     697  procedure ReplaceCont(A, B, Stop: Integer);
    697698  { replace continent name a by b }
    698699  // make sure always continent[loc]<=loc
    699700  var
    700     i: integer;
    701   begin
    702     if a < b then
    703     begin
    704       i := a;
    705       a := b;
    706       b := i
    707     end;
    708     if a > b then
    709       for i := a to Stop do
    710         if Continent[i] = a then
    711           Continent[i] := b
    712   end;
    713 
    714 var
    715   x, y, Loc, Wrong: integer;
    716 begin
    717   for y := 1 to ly - 2 do
    718     for x := 0 to lx - 1 do
    719     begin
    720       Loc := x + lx * y;
     701    I: Integer;
     702  begin
     703    if A < B then
     704    begin
     705      I := A;
     706      A := B;
     707      B := I
     708    end;
     709    if A > B then
     710      for I := A to Stop do
     711        if Continent[I] = A then
     712          Continent[I] := B;
     713  end;
     714
     715var
     716  X, Y, Loc, Wrong: Integer;
     717begin
     718  for Y := 1 to ly - 2 do
     719    for X := 0 to lx - 1 do
     720    begin
     721      Loc := X + lx * Y;
    721722      Continent[Loc] := -1;
    722723      if RealMap[Loc] and fTerrain >= fGrass then
    723724      begin
    724         if (y - 2 >= 1) and (RealMap[Loc - 2 * lx] and fTerrain >= fGrass) then
     725        if (Y - 2 >= 1) and (RealMap[Loc - 2 * lx] and fTerrain >= fGrass) then
    725726          Continent[Loc] := Continent[Loc - 2 * lx];
    726         if (x - 1 + y and 1 >= 0) and (y - 1 >= 1) and
    727           (RealMap[Loc - 1 + y and 1 - lx] and fTerrain >= fGrass) then
    728           Continent[Loc] := Continent[Loc - 1 + y and 1 - lx];
    729         if (x + y and 1 < lx) and (y - 1 >= 1) and
    730           (RealMap[Loc + y and 1 - lx] and fTerrain >= fGrass) then
    731           Continent[Loc] := Continent[Loc + y and 1 - lx];
    732         if (x - 1 >= 0) and (RealMap[Loc - 1] and fTerrain >= fGrass) then
     727        if (X - 1 + Y and 1 >= 0) and (Y - 1 >= 1) and
     728          (RealMap[Loc - 1 + Y and 1 - lx] and fTerrain >= fGrass) then
     729          Continent[Loc] := Continent[Loc - 1 + Y and 1 - lx];
     730        if (X + Y and 1 < lx) and (Y - 1 >= 1) and
     731          (RealMap[Loc + Y and 1 - lx] and fTerrain >= fGrass) then
     732          Continent[Loc] := Continent[Loc + Y and 1 - lx];
     733        if (X - 1 >= 0) and (RealMap[Loc - 1] and fTerrain >= fGrass) then
    733734          if Continent[Loc] = -1 then
    734735            Continent[Loc] := Continent[Loc - 1]
     
    736737            ReplaceCont(Continent[Loc - 1], Continent[Loc], Loc);
    737738        if Continent[Loc] = -1 then
    738           Continent[Loc] := Loc
    739       end
     739          Continent[Loc] := Loc;
     740      end;
    740741    end;
    741742
    742743  { connect continents due to round earth }
    743   for y := 1 to ly - 2 do
    744     if RealMap[lx * y] and fTerrain >= fGrass then
     744  for Y := 1 to ly - 2 do
     745    if RealMap[lx * Y] and fTerrain >= fGrass then
    745746    begin
    746747      Wrong := -1;
    747       if RealMap[lx - 1 + lx * y] and fTerrain >= fGrass then
    748         Wrong := Continent[lx - 1 + lx * y];
    749       if (y and 1 = 0) and (y - 1 >= 1) and
    750         (RealMap[lx - 1 + lx * (y - 1)] and fTerrain >= fGrass) then
    751         Wrong := Continent[lx - 1 + lx * (y - 1)];
    752       if (y and 1 = 0) and (y + 1 < ly - 1) and
    753         (RealMap[lx - 1 + lx * (y + 1)] and fTerrain >= fGrass) then
    754         Wrong := Continent[lx - 1 + lx * (y + 1)];
     748      if RealMap[lx - 1 + lx * Y] and fTerrain >= fGrass then
     749        Wrong := Continent[lx - 1 + lx * Y];
     750      if (Y and 1 = 0) and (Y - 1 >= 1) and
     751        (RealMap[lx - 1 + lx * (Y - 1)] and fTerrain >= fGrass) then
     752        Wrong := Continent[lx - 1 + lx * (Y - 1)];
     753      if (Y and 1 = 0) and (Y + 1 < ly - 1) and
     754        (RealMap[lx - 1 + lx * (Y + 1)] and fTerrain >= fGrass) then
     755        Wrong := Continent[lx - 1 + lx * (Y + 1)];
    755756      if Wrong >= 0 then
    756         ReplaceCont(Wrong, Continent[lx * y], MapSize - 1)
     757        ReplaceCont(Wrong, Continent[lx * Y], MapSize - 1);
    757758    end;
    758759end;
     
    762763// must be done after FindContinents
    763764var
    764   i, j, Cnt, x, y, dx, dy, Loc0, Loc1, xworst, yworst, totalrare, RareMaxWater,
    765     RareType, iBest, jbest, MinDist, xBlock, yBlock, V8: integer;
    766   AreaCount, RareByArea, RareAdjacent: array [0 .. 7, 0 .. 4] of integer;
    767   RareLoc: array [0 .. 11] of integer;
    768   Dist: array [0 .. 11, 0 .. 11] of integer;
     765  I, J, Cnt, X, Y, dx, dy, Loc0, Loc1, xworst, yworst, totalrare, RareMaxWater,
     766    RareType, iBest, jbest, MinDist, xBlock, yBlock, V8: Integer;
     767  AreaCount, RareByArea, RareAdjacent: array [0 .. 7, 0 .. 4] of Integer;
     768  RareLoc: array [0 .. 11] of Integer;
     769  Dist: array [0 .. 11, 0 .. 11] of Integer;
    769770  Adjacent: TVicinity8Loc;
    770771begin
     
    772773  repeat
    773774    FillChar(AreaCount, SizeOf(AreaCount), 0);
    774     for y := 1 to ly - 2 do
    775     begin
    776       yBlock := y * 5 div ly;
    777       if yBlock = (y + 1) * 5 div ly then
    778         for x := 0 to lx - 1 do
    779         begin
    780           xBlock := x * 8 div lx;
    781           if xBlock = (x + 1) * 8 div lx then
     775    for Y := 1 to ly - 2 do
     776    begin
     777      yBlock := Y * 5 div ly;
     778      if yBlock = (Y + 1) * 5 div ly then
     779        for X := 0 to lx - 1 do
     780        begin
     781          xBlock := X * 8 div lx;
     782          if xBlock = (X + 1) * 8 div lx then
    782783          begin
    783             Loc0 := x + lx * y;
     784            Loc0 := X + lx * Y;
    784785            if RealMap[Loc0] and fTerrain >= fGrass then
    785786            begin
     
    791792                if (Loc1 >= 0) and (Loc1 < MapSize) and
    792793                  (RealMap[Loc1] and fTerrain < fGrass) then
    793                   inc(Cnt); // count adjacent water
     794                  Inc(Cnt); // count adjacent water
    794795              end;
    795796              if Cnt <= RareMaxWater then // inner land
    796797              begin
    797                 inc(AreaCount[xBlock, yBlock]);
     798                Inc(AreaCount[xBlock, yBlock]);
    798799                if DelphiRandom(AreaCount[xBlock, yBlock]) = 0 then
    799                   RareByArea[xBlock, yBlock] := Loc0
    800               end
     800                  RareByArea[xBlock, yBlock] := Loc0;
     801              end;
    801802            end;
    802803          end;
    803         end
     804        end;
    804805    end;
    805806    totalrare := 0;
    806     for x := 0 to 7 do
    807       for y := 0 to 4 do
    808         if AreaCount[x, y] > 0 then
    809           inc(totalrare);
    810     inc(RareMaxWater);
     807    for X := 0 to 7 do
     808      for Y := 0 to 4 do
     809        if AreaCount[X, Y] > 0 then
     810          Inc(totalrare);
     811    Inc(RareMaxWater);
    811812  until totalrare >= 12;
    812813
     
    814815  begin // remove rarebyarea resources too close to each other
    815816    FillChar(RareAdjacent, SizeOf(RareAdjacent), 0);
    816     for x := 0 to 7 do
    817       for y := 0 to 4 do
    818         if AreaCount[x, y] > 0 then
    819         begin
    820           if (AreaCount[(x + 1) mod 8, y] > 0) and
    821             (Continent[RareByArea[x, y]] = Continent
    822             [RareByArea[(x + 1) mod 8, y]]) then
     817    for X := 0 to 7 do
     818      for Y := 0 to 4 do
     819        if AreaCount[X, Y] > 0 then
     820        begin
     821          if (AreaCount[(X + 1) mod 8, Y] > 0) and
     822            (Continent[RareByArea[X, Y]] = Continent
     823            [RareByArea[(X + 1) mod 8, Y]]) then
    823824          begin
    824             inc(RareAdjacent[x, y]);
    825             inc(RareAdjacent[(x + 1) mod 8, y]);
     825            Inc(RareAdjacent[X, Y]);
     826            Inc(RareAdjacent[(X + 1) mod 8, Y]);
    826827          end;
    827           if y < 4 then
     828          if Y < 4 then
    828829          begin
    829             if (AreaCount[x, y + 1] > 0) and
    830               (Continent[RareByArea[x, y]] = Continent[RareByArea[x, y + 1]])
     830            if (AreaCount[X, Y + 1] > 0) and
     831              (Continent[RareByArea[X, Y]] = Continent[RareByArea[X, Y + 1]])
    831832            then
    832833            begin
    833               inc(RareAdjacent[x, y]);
    834               inc(RareAdjacent[x, y + 1]);
     834              Inc(RareAdjacent[X, Y]);
     835              Inc(RareAdjacent[X, Y + 1]);
    835836            end;
    836             if (AreaCount[(x + 1) mod 8, y + 1] > 0) and
    837               (Continent[RareByArea[x, y]] = Continent[RareByArea[(x + 1) mod 8,
    838               y + 1]]) then
     837            if (AreaCount[(X + 1) mod 8, Y + 1] > 0) and
     838              (Continent[RareByArea[X, Y]] = Continent[RareByArea[(X + 1) mod 8,
     839              Y + 1]]) then
    839840            begin
    840               inc(RareAdjacent[x, y]);
    841               inc(RareAdjacent[(x + 1) mod 8, y + 1]);
     841              Inc(RareAdjacent[X, Y]);
     842              Inc(RareAdjacent[(X + 1) mod 8, Y + 1]);
    842843            end;
    843             if (AreaCount[(x + 7) mod 8, y + 1] > 0) and
    844               (Continent[RareByArea[x, y]] = Continent[RareByArea[(x + 7) mod 8,
    845               y + 1]]) then
     844            if (AreaCount[(X + 7) mod 8, Y + 1] > 0) and
     845              (Continent[RareByArea[X, Y]] = Continent[RareByArea[(X + 7) mod 8,
     846              Y + 1]]) then
    846847            begin
    847               inc(RareAdjacent[x, y]);
    848               inc(RareAdjacent[(x + 7) mod 8, y + 1]);
     848              Inc(RareAdjacent[X, Y]);
     849              Inc(RareAdjacent[(X + 7) mod 8, Y + 1]);
    849850            end;
    850           end
     851          end;
    851852        end;
    852853    xworst := 0;
    853854    yworst := 0;
    854855    Cnt := 0;
    855     for x := 0 to 7 do
    856       for y := 0 to 4 do
    857         if AreaCount[x, y] > 0 then
    858         begin
    859           if (Cnt = 0) or (RareAdjacent[x, y] > RareAdjacent[xworst, yworst])
     856    for X := 0 to 7 do
     857      for Y := 0 to 4 do
     858        if AreaCount[X, Y] > 0 then
     859        begin
     860          if (Cnt = 0) or (RareAdjacent[X, Y] > RareAdjacent[xworst, yworst])
    860861          then
    861862          begin
    862             xworst := x;
    863             yworst := y;
    864             Cnt := 1
     863            xworst := X;
     864            yworst := Y;
     865            Cnt := 1;
    865866          end
    866           else if (RareAdjacent[x, y] = RareAdjacent[xworst, yworst]) then
     867          else if (RareAdjacent[X, Y] = RareAdjacent[xworst, yworst]) then
    867868          begin
    868             inc(Cnt);
     869            Inc(Cnt);
    869870            if DelphiRandom(Cnt) = 0 then
    870871            begin
    871               xworst := x;
    872               yworst := y;
    873             end
     872              xworst := X;
     873              yworst := Y;
     874            end;
    874875          end;
    875876        end;
    876877    AreaCount[xworst, yworst] := 0;
    877     dec(totalrare)
     878    Dec(totalrare);
    878879  end;
    879880
    880881  Cnt := 0;
    881   for x := 0 to 7 do
    882     for y := 0 to 4 do
    883       if AreaCount[x, y] > 0 then
    884       begin
    885         RareLoc[Cnt] := RareByArea[x, y];
    886         inc(Cnt)
    887       end;
    888   for i := 0 to 11 do
    889   begin
    890     RealMap[RareLoc[i]] := RealMap[RareLoc[i]] and not(fTerrain or fSpecial) or
     882  for X := 0 to 7 do
     883    for Y := 0 to 4 do
     884      if AreaCount[X, Y] > 0 then
     885      begin
     886        RareLoc[Cnt] := RareByArea[X, Y];
     887        Inc(Cnt);
     888      end;
     889  for I := 0 to 11 do
     890  begin
     891    RealMap[RareLoc[I]] := RealMap[RareLoc[I]] and not(fTerrain or fSpecial) or
    891892      (fDesert or fDeadLands);
    892893    for dy := -1 to 1 do
     
    894895        if (dx + dy) and 1 = 0 then
    895896        begin
    896           Loc1 := dLoc(RareLoc[i], dx, dy);
     897          Loc1 := dLoc(RareLoc[I], dx, dy);
    897898          if (Loc1 >= 0) and (RealMap[Loc1] and fTerrain = fMountains) then
    898899            RealMap[Loc1] := RealMap[Loc1] and not fTerrain or fHills;
    899         end
    900   end;
    901   for i := 0 to 11 do
    902     for j := 0 to 11 do
    903       Dist[i, j] := Distance(RareLoc[i], RareLoc[j]);
     900        end;
     901  end;
     902  for I := 0 to 11 do
     903    for J := 0 to 11 do
     904      Dist[I, J] := Distance(RareLoc[I], RareLoc[J]);
    904905
    905906  ibest := 0;
     
    909910  begin
    910911    Cnt := 0;
    911     for i := 0 to 11 do
    912       if RareLoc[i] >= 0 then
    913         for j := 0 to 11 do
    914           if RareLoc[j] >= 0 then
     912    for I := 0 to 11 do
     913      if RareLoc[I] >= 0 then
     914        for J := 0 to 11 do
     915          if RareLoc[J] >= 0 then
    915916            if (Cnt > 0) and (Dist[iBest, jbest] >= MinDist) then
    916917            begin
    917               if Dist[i, j] >= MinDist then
     918              if Dist[I, J] >= MinDist then
    918919              begin
    919                 inc(Cnt);
     920                Inc(Cnt);
    920921                if DelphiRandom(Cnt) = 0 then
    921922                begin
    922                   iBest := i;
    923                   jbest := j
    924                 end
    925               end
     923                  iBest := I;
     924                  jbest := J;
     925                end;
     926              end;
    926927            end
    927             else if (Cnt = 0) or (Dist[i, j] > Dist[iBest, jbest]) then
     928            else if (Cnt = 0) or (Dist[I, J] > Dist[iBest, jbest]) then
    928929            begin
    929               iBest := i;
    930               jbest := j;
     930              iBest := I;
     931              jbest := J;
    931932              Cnt := 1;
    932933            end;
     
    938939    RareLoc[jbest] := -1;
    939940  end;
    940 end; // RarePositions
    941 
    942 function CheckShore(Loc: integer): boolean;
    943 var
    944   Loc1, OldTile, V21: integer;
     941end;
     942
     943function CheckShore(Loc: Integer): Boolean;
     944var
     945  Loc1, OldTile, V21: Integer;
    945946  Radius: TVicinity21Loc;
    946947begin
    947   result := false;
     948  Result := False;
    948949  OldTile := RealMap[Loc];
    949950  if OldTile and fTerrain < fGrass then
     
    960961    end;
    961962    if (RealMap[Loc] xor Cardinal(OldTile)) and fTerrain <> 0 then
    962       result := true;
    963   end;
    964 end;
    965 
    966 function ActualSpecialTile(Loc: integer): Cardinal;
    967 begin
    968   result := SpecialTile(Loc, RealMap[Loc] and fTerrain, lx);
    969 end;
    970 
    971 procedure CreateMap(preview: boolean);
     963      Result := True;
     964  end;
     965end;
     966
     967function ActualSpecialTile(Loc: Integer): Cardinal;
     968begin
     969  Result := SpecialTile(Loc, RealMap[Loc] and fTerrain, lx);
     970end;
     971
     972procedure CreateMap(preview: Boolean);
    972973const
    973974  ShHiHills = 6; { of land }
     
    980981  hotunification = 50; // min. 25
    981982
    982   Zone: array [0 .. 3, 2 .. 9] of single = { terrain distribution }
     983  Zone: array [0 .. 3, 2 .. 9] of Single = { terrain distribution }
    983984    ((0.25, 0, 0, 0.4, 0, 0, 0, 0.35), (0.55, 0, 0.1, 0, 0, 0, 0, 0.35),
    984985    (0.4, 0, 0.35, 0, 0, 0, 0, 0.25), (0, 0.7, 0, 0, 0, 0, 0, 0.3));
    985986  { Grs  Dst  Pra  Tun  - - - For }
    986987
    987   function RndLow(y: integer): Cardinal;
     988  function RndLow(Y: Integer): Cardinal;
    988989  { random lowland appropriate to climate }
    989990  var
    990     z0, i: integer;
    991     p, p0, ZPlus: single;
    992   begin
    993     if ly - 1 - y > y then
    994     begin
    995       z0 := 6 * y div ly;
    996       ZPlus := 6 * y / ly - z0;
     991    z0, I: Integer;
     992    P, p0, ZPlus: Single;
     993  begin
     994    if ly - 1 - Y > Y then
     995    begin
     996      z0 := 6 * Y div ly;
     997      ZPlus := 6 * Y / ly - z0;
    997998    end
    998999    else
    9991000    begin
    1000       z0 := 6 * (ly - 1 - y) div ly;
    1001       ZPlus := 6 * (ly - 1 - y) / ly - z0;
     1001      z0 := 6 * (ly - 1 - Y) div ly;
     1002      ZPlus := 6 * (ly - 1 - Y) / ly - z0;
    10021003    end;
    10031004    p0 := 1;
    1004     for i := 2 to 9 do
    1005     begin
    1006       p := Zone[z0, i] * (1 - ZPlus) + Zone[z0 + 1, i] * ZPlus;
     1005    for I := 2 to 9 do
     1006    begin
     1007      P := Zone[z0, I] * (1 - ZPlus) + Zone[z0 + 1, I] * ZPlus;
    10071008      { weight between zones z0 and z0+1 }
    1008       if DelphiRandom * p0 < p then
    1009       begin
    1010         RndLow := i;
     1009      if DelphiRandom * p0 < P then
     1010      begin
     1011        RndLow := I;
    10111012        Break;
    10121013      end;
    1013       p0 := p0 - p;
    1014     end;
    1015   end;
    1016 
    1017   function RunRiver(Loc0: integer): integer;
     1014      p0 := p0 - P;
     1015    end;
     1016  end;
     1017
     1018  function RunRiver(Loc0: Integer): Integer;
    10181019  { runs river from start point Loc0; return value: length }
    10191020  var
    1020     Dir, T, Loc, Loc1, Cost: integer;
     1021    Dir, T, Loc, Loc1, Cost: Integer;
    10211022    Q: TIPQ;
    1022     From: array [0 .. lxmax * lymax - 1] of integer;
    1023     Time: array [0 .. lxmax * lymax - 1] of integer;
    1024     OneTileLake: boolean;
     1023    From: array [0 .. lxmax * lymax - 1] of Integer;
     1024    Time: array [0 .. lxmax * lymax - 1] of Integer;
     1025    OneTileLake: Boolean;
    10251026  begin
    10261027    FillChar(Time, SizeOf(Time), 255); { -1 }
     
    10311032      if (RealMap[Loc] and fTerrain < fGrass) then
    10321033      begin
    1033         OneTileLake := true;
     1034        OneTileLake := True;
    10341035        for Dir := 0 to 3 do
    10351036        begin
    10361037          Loc1 := dLoc(Loc, Dir and 1 * 2 - 1, Dir shr 1 * 2 - 1);
    10371038          if (Loc1 >= 0) and (RealMap[Loc1] and fTerrain < fGrass) then
    1038             OneTileLake := false;
     1039            OneTileLake := False;
    10391040        end;
    10401041        if not OneTileLake then
     
    10611062    end;
    10621063    Loc1 := Loc;
    1063     result := 0;
     1064    Result := 0;
    10641065    while Loc <> Loc0 do
    10651066    begin
    10661067      Loc := From[Loc];
    1067       inc(result);
    1068     end;
    1069     if (result > 1) and ((result >= MinRivLen) or
     1068      Inc(Result);
     1069    end;
     1070    if (Result > 1) and ((Result >= MinRivLen) or
    10701071      (RealMap[Loc1] and fTerrain >= fGrass)) then
    10711072    begin
     
    10811082    end
    10821083    else
    1083       result := 0;
     1084      Result := 0;
    10841085    FreeAndNil(Q);
    10851086  end;
    10861087
    10871088var
    1088   x, y, n, Dir, plus, Count, Loc0, Loc1, bLand, bHills, bMountains, V8: integer;
    1089   CopyFrom: array [0 .. lxmax * lymax - 1] of integer;
     1089  X, Y, N, Dir, plus, Count, Loc0, Loc1, bLand, bHills, bMountains, V8: Integer;
     1090  CopyFrom: array [0 .. lxmax * lymax - 1] of Integer;
    10901091  Adjacent: TVicinity8Loc;
    10911092
     
    10961097  while plus < MapSize * LandMass * ShMountains div 10000 do
    10971098  begin
    1098     dec(bMountains);
    1099     inc(plus, ElCount[bMountains])
     1099    Dec(bMountains);
     1100    Inc(plus, ElCount[bMountains]);
    11001101  end;
    11011102  Count := plus;
     
    11041105  while plus < MapSize * LandMass * ShHiHills div 10000 do
    11051106  begin
    1106     dec(bHills);
    1107     inc(plus, ElCount[bHills])
    1108   end;
    1109   inc(Count, plus);
     1107    Dec(bHills);
     1108    Inc(plus, ElCount[bHills]);
     1109  end;
     1110  Inc(Count, plus);
    11101111  bLand := bHills;
    11111112  while Count < MapSize * LandMass div 100 do
    11121113  begin
    1113     dec(bLand);
    1114     inc(Count, ElCount[bLand])
     1114    Dec(bLand);
     1115    Inc(Count, ElCount[bLand]);
    11151116  end;
    11161117
     
    11351136          (RealMap[Loc1] and fTerrain < fGrass) or
    11361137          (RealMap[Loc1] and fTerrain = fArctic) then
    1137           inc(Count); // count adjacent water
     1138          Inc(Count); // count adjacent water
    11381139      end;
    11391140      if Count = 8 then
    1140         RealMap[Loc0] := fOcean
     1141        RealMap[Loc0] := fOcean;
    11411142    end;
    11421143
     
    11471148      plus := MapSize;
    11481149    Loc0 := DelphiRandom(MapSize);
    1149     for n := 0 to plus - 1 do
     1150    for N := 0 to plus - 1 do
    11501151    begin
    11511152      if (RealMap[Loc0] and fTerrain >= fGrass) and (Loc0 >= lx) and
     
    11641165    CopyFrom[Loc0] := Loc0;
    11651166
    1166   for n := 0 to unification * MapSize div 100 do
    1167   begin
    1168     y := DelphiRandom(ly);
    1169     if abs(y - (ly shr 1)) > ly div 4 + DelphiRandom(ly * hotunification div 100) then
    1170       if y < ly shr 1 then
    1171         y := ly shr 1 - y
     1167  for N := 0 to unification * MapSize div 100 do
     1168  begin
     1169    Y := DelphiRandom(ly);
     1170    if abs(Y - (ly shr 1)) > ly div 4 + DelphiRandom(ly * hotunification div 100) then
     1171      if Y < ly shr 1 then
     1172        Y := ly shr 1 - Y
    11721173      else
    1173         y := 3 * ly shr 1 - y;
    1174     Loc0 := lx * y + DelphiRandom(lx);
     1174        Y := 3 * ly shr 1 - Y;
     1175    Loc0 := lx * Y + DelphiRandom(lx);
    11751176    if RealMap[Loc0] and fTerrain = fGrass then
    11761177    begin
     
    12021203        Loc1 := CopyFrom[Loc1];
    12031204      RealMap[Loc0] := RealMap[Loc0] and not fTerrain or
    1204         RealMap[Loc1] and fTerrain
     1205        RealMap[Loc1] and fTerrain;
    12051206    end;
    12061207
     
    12251226          if Loc1 >= 0 then
    12261227            if RealMap[Loc1] and fTerrain < fGrass then
    1227               inc(Count, 2)
     1228              Inc(Count, 2);
    12281229        end;
    12291230      end;
    12301231      if Count >= 4 then
    1231         RealMap[Loc0] := RealMap[Loc0] and not fTerrain or fPrairie
     1232        RealMap[Loc0] := RealMap[Loc0] and not fTerrain or fPrairie;
    12321233    end;
    12331234
     
    12411242        if Loc1 >= 0 then
    12421243          if RealMap[Loc1] and fTerrain <> fDesert then
    1243             inc(Count)
     1244            Inc(Count);
    12441245      end;
    12451246      if Count >= 4 then
    1246         RealMap[Loc0] := RealMap[Loc0] and not fTerrain or fPrairie
     1247        RealMap[Loc0] := RealMap[Loc0] and not fTerrain or fPrairie;
    12471248    end;
    12481249
    12491250  for Loc0 := 0 to MapSize - 1 do
    12501251    CheckShore(Loc0); // change ocean to shore
    1251   for x := 0 to lx - 1 do
    1252   begin
    1253     RealMap[x + lx * 0] := fArctic;
    1254     if RealMap[x + lx * 1] >= fGrass then
    1255       RealMap[x + lx * 1] := RealMap[x + lx * 1] and not fTerrain or fTundra;
    1256     if RealMap[x + lx * (ly - 2)] >= fGrass then
    1257       RealMap[x + lx * (ly - 2)] := RealMap[x + lx * (ly - 2)] and
     1252  for X := 0 to lx - 1 do
     1253  begin
     1254    RealMap[X + lx * 0] := fArctic;
     1255    if RealMap[X + lx * 1] >= fGrass then
     1256      RealMap[X + lx * 1] := RealMap[X + lx * 1] and not fTerrain or fTundra;
     1257    if RealMap[X + lx * (ly - 2)] >= fGrass then
     1258      RealMap[X + lx * (ly - 2)] := RealMap[X + lx * (ly - 2)] and
    12581259        not fTerrain or fTundra;
    1259     RealMap[x + lx * (ly - 1)] := fArctic
     1260    RealMap[X + lx * (ly - 1)] := fArctic;
    12601261  end;
    12611262
     
    12781279  CountGood: (cgBest, cgFlat, cgLand);
    12791280
    1280   function IsGoodTile(Loc: integer): boolean;
     1281  function IsGoodTile(Loc: Integer): Boolean;
    12811282  var
    1282     xLoc, yLoc: integer;
     1283    xLoc, yLoc: Integer;
    12831284  begin
    12841285    xLoc := Loc mod lx;
    12851286    yLoc := Loc div lx;
    12861287    if RealMap[Loc] and fDeadLands <> 0 then
    1287       result := false
     1288      Result := False
    12881289    else
    12891290      case CountGood of
    12901291        cgBest:
    1291           result := (RealMap[Loc] and fTerrain in [fGrass, fPrairie, fTundra,
     1292          Result := (RealMap[Loc] and fTerrain in [fGrass, fPrairie, fTundra,
    12921293            fSwamp, fForest]) and Odd((lymax + xLoc - yLoc shr 1) shr 1 + xLoc +
    12931294            (yLoc + 1) shr 1);
    12941295        cgFlat:
    1295           result := (RealMap[Loc] and fTerrain in [fGrass, fPrairie, fTundra,
     1296          Result := (RealMap[Loc] and fTerrain in [fGrass, fPrairie, fTundra,
    12961297            fSwamp, fForest]);
    12971298        cgLand:
    1298           result := RealMap[Loc] and fTerrain >= fGrass;
     1299          Result := RealMap[Loc] and fTerrain >= fGrass;
    12991300      end;
    13001301  end;
     
    13041305
    13051306var
    1306   p1, p2, nAlive, c, Loc, Loc1, CntGood, CntGoodGrass, MinDist, i, j, n,
     1307  p1, p2, nAlive, C, Loc, Loc1, CntGood, CntGoodGrass, MinDist, I, J, N,
    13071308    nsc, V21, V8, BestDist, TestDist, MinGood, nIrrLoc,
    1308     FineDistSQR, nRest: integer;
    1309   ccount: array [0 .. lxmax * lymax - 1] of word;
    1310   sc, StartLoc0, sccount: array [1 .. nPl] of integer;
    1311   TestStartLoc: array [0 .. nPl - 1] of integer;
    1312   CityLoc: array [1 .. nPl, 0 .. MaxCityLoc - 1] of integer;
    1313   nCityLoc: array [1 .. nPl] of integer;
    1314   RestLoc: array [0 .. MaxCityLoc - 1] of integer;
    1315   IrrLoc: array [0 .. 20] of integer;
     1309    FineDistSQR, nRest: Integer;
     1310  ccount: array [0 .. lxmax * lymax - 1] of Word;
     1311  sc, StartLoc0, sccount: array [1 .. nPl] of Integer;
     1312  TestStartLoc: array [0 .. nPl - 1] of Integer;
     1313  CityLoc: array [1 .. nPl, 0 .. MaxCityLoc - 1] of Integer;
     1314  nCityLoc: array [1 .. nPl] of Integer;
     1315  RestLoc: array [0 .. MaxCityLoc - 1] of Integer;
     1316  IrrLoc: array [0 .. 20] of Integer;
    13161317  Radius: TVicinity21Loc;
    13171318  Adjacent: TVicinity8Loc;
    1318   ok: boolean;
     1319  ok: Boolean;
    13191320
    13201321begin
     
    13221323  for p1 := 0 to nPl - 1 do
    13231324    if 1 shl p1 and GAlive <> 0 then
    1324       inc(nAlive);
     1325      Inc(nAlive);
    13251326  if nAlive = 0 then
    1326     exit;
     1327    Exit;
    13271328
    13281329  { count good tiles }
     
    13311332    if RealMap[Loc] and fTerrain = fGrass then
    13321333      if ActualSpecialTile(Loc) = 1 then
    1333         inc(ccount[Continent[Loc]], 3)
     1334        Inc(ccount[Continent[Loc]], 3)
    13341335      else
    1335         inc(ccount[Continent[Loc]], 2)
     1336        Inc(ccount[Continent[Loc]], 2)
    13361337    else if RealMap[Loc] and fTerrain in [fPrairie, fSwamp, fForest, fHills]
    13371338    then
    1338       inc(ccount[Continent[Loc]]);
     1339      Inc(ccount[Continent[Loc]]);
    13391340
    13401341  Loc := 0;
    13411342  while ccount[Loc] > 0 do
    1342     inc(Loc);
    1343   for i := 1 to nAlive do
    1344   begin
    1345     sc[i] := Loc;
    1346     sccount[i] := 1
     1343    Inc(Loc);
     1344  for I := 1 to nAlive do
     1345  begin
     1346    sc[I] := Loc;
     1347    sccount[I] := 1
    13471348  end;
    13481349  { init with zero size start continents, then search bigger ones }
     
    13551356        if p1 < nAlive + 1 then
    13561357          sc[p1] := sc[p1 - 1];
    1357         dec(p1)
     1358        Dec(p1);
    13581359      end;
    13591360      if p1 < nAlive + 1 then
     
    13621363  nsc := nAlive;
    13631364  repeat
    1364     c := 1; // search least crowded continent after smallest
    1365     for i := 2 to nsc - 1 do
    1366       if ccount[sc[i]] * (2 * sccount[c] + 1) > ccount[sc[c]] *
    1367         (2 * sccount[i] + 1) then
    1368         c := i;
    1369     if ccount[sc[nsc]] * (2 * sccount[c] + 1) > ccount[sc[c]] then
     1365    C := 1; // search least crowded continent after smallest
     1366    for I := 2 to nsc - 1 do
     1367      if ccount[sc[I]] * (2 * sccount[C] + 1) > ccount[sc[C]] *
     1368        (2 * sccount[I] + 1) then
     1369        C := I;
     1370    if ccount[sc[nsc]] * (2 * sccount[C] + 1) > ccount[sc[C]] then
    13701371      Break; // even least crowded continent is more crowded than smallest
    1371     inc(sccount[c]);
    1372     dec(nsc)
     1372    Inc(sccount[C]);
     1373    Dec(nsc);
    13731374  until sccount[nsc] > 1;
    13741375
     
    13761377  CountGood := cgBest;
    13771378  repeat
    1378     dec(MinGood);
     1379    Dec(MinGood);
    13791380    if (MinGood = 3) and (CountGood < cgLand) then // too demanding!
    13801381    begin
    1381       inc(CountGood);
    1382       MinGood := 6
     1382      Inc(CountGood);
     1383      MinGood := 6;
    13831384    end;
    13841385    FillChar(nCityLoc, SizeOf(nCityLoc), 0);
    13851386    Loc := DelphiRandom(MapSize);
    1386     for i := 0 to MapSize - 1 do
     1387    for I := 0 to MapSize - 1 do
    13871388    begin
    13881389      if ((Loc >= 4 * lx) and (Loc < MapSize - 4 * lx) or (CountGood >= cgLand))
    13891390        and IsGoodTile(Loc) then
    13901391      begin
    1391         c := nsc;
    1392         while (c > 0) and (Continent[Loc] <> sc[c]) do
    1393           dec(c);
    1394         if (c > 0) and (nCityLoc[c] < MaxCityLoc) then
     1392        C := nsc;
     1393        while (C > 0) and (Continent[Loc] <> sc[C]) do
     1394          Dec(C);
     1395        if (C > 0) and (nCityLoc[C] < MaxCityLoc) then
    13951396        begin
    13961397          CntGood := 1;
     
    14011402              Loc1 := Radius[V21];
    14021403              if (Loc1 >= 0) and (Loc1 < MapSize) and IsGoodTile(Loc1) then
    1403                 inc(CntGood)
     1404                Inc(CntGood);
    14041405            end;
    14051406          if CntGood >= MinGood then
    14061407          begin
    1407             CityLoc[c, nCityLoc[c]] := Loc;
    1408             inc(nCityLoc[c])
     1408            CityLoc[C, nCityLoc[C]] := Loc;
     1409            Inc(nCityLoc[C]);
    14091410          end;
    14101411        end;
     
    14131414    end;
    14141415
    1415     ok := true;
    1416     for c := 1 to nsc do
    1417       if nCityLoc[c] < sccount[c] * (8 - MinGood) div (7 - MinGood) then
    1418         ok := false;
     1416    ok := True;
     1417    for C := 1 to nsc do
     1418      if nCityLoc[C] < sccount[C] * (8 - MinGood) div (7 - MinGood) then
     1419        ok := False;
    14191420  until ok;
    14201421
    14211422  FineDistSQR := MapSize * LandMass * 9 div (nAlive * 100);
    14221423  p1 := 1;
    1423   for c := 1 to nsc do
     1424  for C := 1 to nsc do
    14241425  begin // for all start continents
    1425     if sccount[c] = 1 then
    1426       StartLoc0[p1] := CityLoc[c, DelphiRandom(nCityLoc[c])]
     1426    if sccount[C] = 1 then
     1427      StartLoc0[p1] := CityLoc[C, DelphiRandom(nCityLoc[C])]
    14271428    else
    14281429    begin
    14291430      BestDist := 0;
    1430       n := 1 shl sccount[c] * 32; // number of tries to find good distribution
    1431       if n > 1 shl 12 then
    1432         n := 1 shl 12;
    1433       while (n > 0) and (BestDist * BestDist < FineDistSQR) do
     1431      N := 1 shl sccount[C] * 32; // number of tries to find good distribution
     1432      if N > 1 shl 12 then
     1433        N := 1 shl 12;
     1434      while (N > 0) and (BestDist * BestDist < FineDistSQR) do
    14341435      begin
    14351436        MinDist := MaxInt;
    1436         nRest := nCityLoc[c];
    1437         for i := 0 to nRest - 1 do
    1438           RestLoc[i] := CityLoc[c, i];
    1439         for i := 0 to sccount[c] - 1 do
     1437        nRest := nCityLoc[C];
     1438        for I := 0 to nRest - 1 do
     1439          RestLoc[I] := CityLoc[C, I];
     1440        for I := 0 to sccount[C] - 1 do
    14401441        begin
    14411442          if nRest = 0 then
    14421443            Break;
    1443           j := DelphiRandom(nRest);
    1444           TestStartLoc[i] := RestLoc[j];
    1445           RestLoc[j] := RestLoc[nRest - 1];
    1446           dec(nRest);
    1447           for j := 0 to i - 1 do
     1444          J := DelphiRandom(nRest);
     1445          TestStartLoc[I] := RestLoc[J];
     1446          RestLoc[J] := RestLoc[nRest - 1];
     1447          Dec(nRest);
     1448          for J := 0 to I - 1 do
    14481449          begin
    1449             TestDist := Distance(TestStartLoc[i], TestStartLoc[j]);
     1450            TestDist := Distance(TestStartLoc[I], TestStartLoc[J]);
    14501451            if TestDist < MinDist then
    1451               MinDist := TestDist
     1452              MinDist := TestDist;
    14521453          end;
    1453           if i = sccount[c] - 1 then
     1454          if I = sccount[C] - 1 then
    14541455          begin
    1455             assert(MinDist > BestDist);
     1456            Assert(MinDist > BestDist);
    14561457            BestDist := MinDist;
    1457             for j := 0 to sccount[c] - 1 do
    1458               StartLoc0[p1 + j] := TestStartLoc[j];
     1458            for J := 0 to sccount[C] - 1 do
     1459              StartLoc0[p1 + J] := TestStartLoc[J];
    14591460          end
    14601461          else if BestDist > 0 then
    14611462          begin
    1462             j := 0;
    1463             while j < nRest do
     1463            J := 0;
     1464            while J < nRest do
    14641465            begin // remove all locs from rest which have too little distance to this one
    1465               TestDist := Distance(TestStartLoc[i], RestLoc[j]);
     1466              TestDist := Distance(TestStartLoc[I], RestLoc[J]);
    14661467              if TestDist <= BestDist then
    14671468              begin
    1468                 RestLoc[j] := RestLoc[nRest - 1];
    1469                 dec(nRest);
     1469                RestLoc[J] := RestLoc[nRest - 1];
     1470                Dec(nRest);
    14701471              end
    14711472              else
    1472                 inc(j);
     1473                Inc(J);
    14731474            end;
    14741475          end;
    14751476        end;
    1476         dec(n)
    1477       end;
    1478     end;
    1479     p1 := p1 + sccount[c]
     1477        Dec(N)
     1478      end;
     1479    end;
     1480    p1 := p1 + sccount[C]
    14801481  end;
    14811482
     
    14941495        if (Loc1 >= 0) and (Loc1 < MapSize) and IsGoodTile(Loc1) then
    14951496          if RealMap[Loc1] and fTerrain = fGrass then
    1496             inc(CntGoodGrass)
     1497            Inc(CntGoodGrass)
    14971498          else
    1498             inc(CntGood);
     1499            Inc(CntGood);
    14991500      end;
    15001501    for V21 := 1 to 26 do
     
    15281529        begin
    15291530          IrrLoc[nIrrLoc] := Loc1;
    1530           inc(nIrrLoc);
    1531         end;
    1532       end;
    1533     i := 2;
    1534     if i > nIrrLoc then
    1535       i := nIrrLoc;
    1536     while i > 0 do
    1537     begin
    1538       j := DelphiRandom(nIrrLoc);
    1539       RealMap[IrrLoc[j]] := RealMap[IrrLoc[j]] or tiIrrigation;
    1540       IrrLoc[j] := IrrLoc[nIrrLoc - 1];
    1541       dec(nIrrLoc);
    1542       dec(i);
     1531          Inc(nIrrLoc);
     1532        end;
     1533      end;
     1534    I := 2;
     1535    if I > nIrrLoc then
     1536      I := nIrrLoc;
     1537    while I > 0 do
     1538    begin
     1539      J := DelphiRandom(nIrrLoc);
     1540      RealMap[IrrLoc[J]] := RealMap[IrrLoc[J]] or tiIrrigation;
     1541      IrrLoc[J] := IrrLoc[nIrrLoc - 1];
     1542      Dec(nIrrLoc);
     1543      Dec(I);
    15431544    end;
    15441545  end;
     
    15491550    begin
    15501551      repeat
    1551         i := DelphiRandom(nAlive) + 1
    1552       until StartLoc0[i] >= 0;
    1553       StartLoc[p1] := StartLoc0[i];
    1554       StartLoc0[i] := -1
     1552        I := DelphiRandom(nAlive) + 1
     1553      until StartLoc0[I] >= 0;
     1554      StartLoc[p1] := StartLoc0[I];
     1555      StartLoc0[I] := -1
    15551556    end;
    15561557  SaveMapCenterLoc := StartLoc[0];
     
    15851586          StartLoc2[p1] := Loc1;
    15861587          BestDist := TestDist;
    1587           n := 1;
     1588          N := 1;
    15881589        end
    15891590        else if TestDist = BestDist then
    15901591        begin
    1591           inc(n);
    1592           if DelphiRandom(n) = 0 then
     1592          Inc(N);
     1593          if DelphiRandom(N) = 0 then
    15931594            StartLoc2[p1] := Loc1;
    15941595        end;
    15951596      end;
    15961597    end;
    1597 end; { StartPositions }
    1598 
    1599 procedure PredefinedStartPositions(Human: integer);
     1598end;
     1599
     1600procedure PredefinedStartPositions(Human: Integer);
    16001601// use predefined nation start positions
    16011602var
    1602   i, p1, Loc1, nAlive, nStartLoc0, nPrefStartLoc0, imax: integer;
    1603   StartLoc0: array [0 .. lxmax * lymax - 1] of integer;
    1604   ishuman: boolean;
     1603  I, p1, Loc1, nAlive, nStartLoc0, nPrefStartLoc0, imax: Integer;
     1604  StartLoc0: array [0 .. lxmax * lymax - 1] of Integer;
     1605  ishuman: Boolean;
    16051606begin
    16061607  nAlive := 0;
    16071608  for p1 := 0 to nPl - 1 do
    16081609    if 1 shl p1 and GAlive <> 0 then
    1609       inc(nAlive);
     1610      Inc(nAlive);
    16101611  if nAlive = 0 then
    1611     exit;
     1612    Exit;
    16121613
    16131614  for I := 0 to Length(StartLoc0) - 1 do
     
    16221623      StartLoc0[nStartLoc0] := StartLoc0[nPrefStartLoc0];
    16231624      StartLoc0[nPrefStartLoc0] := Loc1;
    1624       inc(nPrefStartLoc0);
    1625       inc(nStartLoc0);
     1625      Inc(nPrefStartLoc0);
     1626      Inc(nStartLoc0);
    16261627      RealMap[Loc1] := RealMap[Loc1] and not fPrefStartPos;
    16271628    end
     
    16291630    begin
    16301631      StartLoc0[nStartLoc0] := Loc1;
    1631       inc(nStartLoc0);
     1632      Inc(nStartLoc0);
    16321633      RealMap[Loc1] := RealMap[Loc1] and not fStartPos;
    16331634    end;
    1634   assert(nStartLoc0 >= nAlive);
     1635  Assert(nStartLoc0 >= nAlive);
    16351636
    16361637  StartLoc[0] := 0;
    1637   for ishuman := true downto false do
     1638  for ishuman := True downto False do
    16381639    for p1 := 0 to nPl - 1 do
    16391640      if (1 shl p1 and GAlive <> 0) and ((1 shl p1 and Human <> 0) = ishuman)
    16401641      then
    16411642      begin
    1642         dec(nStartLoc0);
     1643        Dec(nStartLoc0);
    16431644        imax := nStartLoc0;
    16441645        if nPrefStartLoc0 > 0 then
    16451646        begin
    1646           dec(nPrefStartLoc0);
     1647          Dec(nPrefStartLoc0);
    16471648          imax := nPrefStartLoc0;
    16481649        end;
    1649         i := DelphiRandom(imax + 1);
    1650         StartLoc[p1] := StartLoc0[i];
    1651         StartLoc2[p1] := StartLoc0[i];
    1652         StartLoc0[i] := StartLoc0[imax];
     1650        I := DelphiRandom(imax + 1);
     1651        StartLoc[p1] := StartLoc0[I];
     1652        StartLoc2[p1] := StartLoc0[I];
     1653        StartLoc0[I] := StartLoc0[imax];
    16531654        StartLoc0[imax] := StartLoc0[nStartLoc0];
    16541655      end;
    16551656  SaveMapCenterLoc := StartLoc[0];
    1656 end; { PredefinedStartPositions }
     1657end;
    16571658
    16581659procedure InitGame;
    16591660var
    1660   i, p, p1, uix, Loc1: integer;
     1661  I, P, p1, uix, Loc1: Integer;
    16611662begin
    16621663  {$IFDEF FastContact}
     
    16701671    if RealMap[Loc1] and fterrain>=fGrass then
    16711672    if Delphirandom(3)=0 then RealMap[Loc1]:=RealMap[Loc1] or fRoad
    1672     else if Delphirandom(3)=0 then RealMap[Loc1]:=RealMap[Loc1] or fRR;
     1673    else if Delphirandom(3)=0 then RealMap[Loc1]:=RealMap[Loc1] or fRR;}
    16731674    {random Road and Railroad }
    16741675  { !!!for Loc1:=0 to MapSize-1 do
     
    16821683  GTestFlags := 0;
    16831684  GInitialized := GAlive or GWatching;
    1684   for p := 0 to nPl - 1 do
    1685     if 1 shl p and GInitialized <> 0 then
    1686       with RW[p] do
    1687       begin
    1688         Researched[p] := 0;
    1689         Discovered[p] := 0;
    1690         TerritoryCount[p] := 0;
    1691         nTech[p] := 0;
    1692         if Difficulty[p] = 0 then
    1693           ResourceMask[p] := $FFFFFFFF
     1685  for P := 0 to nPl - 1 do
     1686    if 1 shl P and GInitialized <> 0 then
     1687      with RW[P] do
     1688      begin
     1689        Researched[P] := 0;
     1690        Discovered[P] := 0;
     1691        TerritoryCount[P] := 0;
     1692        nTech[P] := 0;
     1693        if Difficulty[P] = 0 then
     1694          ResourceMask[P] := $FFFFFFFF
    16941695        else
    1695           ResourceMask[p] := $FFFFFFFF and not(fSpecial2 or fModern);
    1696         GrWallContinent[p] := -1;
     1696          ResourceMask[P] := $FFFFFFFF and not(fSpecial2 or fModern);
     1697        GrWallContinent[P] := -1;
    16971698
    16981699        GetMem(Map, 4 * MapSize);
     
    17121713          if 1 shl p1 and GInitialized <> 0 then
    17131714          begin
    1714             FillChar(RWemix[p, p1], SizeOf(RWemix[p, p1]), 255); { -1 }
    1715             FillChar(Destroyed[p, p1], SizeOf(Destroyed[p, p1]), 0);
     1715            FillChar(RWemix[P, p1], SizeOf(RWemix[P, p1]), 255); { -1 }
     1716            FillChar(Destroyed[P, p1], SizeOf(Destroyed[P, p1]), 0);
    17161717          end;
    17171718          Attitude[p1] := atNeutral;
     
    17211722          Tribute[p1] := 0;
    17221723          TributePaid[p1] := 0;
    1723           if (p1 <> p) and (1 shl p1 and GAlive <> 0) then
     1724          if (p1 <> P) and (1 shl p1 and GAlive <> 0) then
    17241725          begin // initialize enemy report
    17251726            GetMem(EnemyReport[p1], SizeOf(TEnemyReport) - 2 *
     
    17311732            EnemyReport[p1].Attitude := atNeutral;
    17321733            EnemyReport[p1].Government := gDespotism;
    1733             if 1 shl p and GAlive = 0 then
     1734            if 1 shl P and GAlive = 0 then
    17341735              Treaty[p1] := trNone // supervisor
    17351736          end
     
    17531754
    17541755  // create initial models and units
    1755   for p := 0 to nPl - 1 do
    1756     if (1 shl p and GAlive <> 0) then
    1757       with RW[p] do
     1756  for P := 0 to nPl - 1 do
     1757    if (1 shl P and GAlive <> 0) then
     1758      with RW[P] do
    17581759      begin
    17591760        nModel := 0;
    1760         for i := 0 to nSpecialModel - 1 do
    1761           if SpecialModelPreq[i] = preNone then
     1761        for I := 0 to nSpecialModel - 1 do
     1762          if SpecialModelPreq[I] = preNone then
    17621763          begin
    1763             Model[nModel] := SpecialModel[i];
     1764            Model[nModel] := SpecialModel[I];
    17641765            Model[nModel].Status := 0;
    17651766            Model[nModel].IntroTurn := 0;
    17661767            Model[nModel].Built := 0;
    17671768            Model[nModel].Lost := 0;
    1768             Model[nModel].ID := p shl 12 + nModel;
     1769            Model[nModel].ID := P shl 12 + nModel;
    17691770            SetModelFlags(Model[nModel]);
    1770             inc(nModel)
     1771            Inc(nModel);
    17711772          end;
    17721773        nUn := 0;
    1773         UnBuilt[p] := 0;
     1774        UnBuilt[P] := 0;
    17741775        for uix := 0 to nStartUn - 1 do
    17751776        begin
    1776           CreateUnit(p, StartUn[uix]);
    1777           dec(Model[StartUn[uix]].Built);
    1778           Un[uix].Loc := StartLoc2[p];
    1779           PlaceUnit(p, uix);
    1780         end;
    1781         FoundCity(p, StartLoc[p]); // capital
    1782         Founded[p] := 1;
     1777          CreateUnit(P, StartUn[uix]);
     1778          Dec(Model[StartUn[uix]].Built);
     1779          Un[uix].Loc := StartLoc2[P];
     1780          PlaceUnit(P, uix);
     1781        end;
     1782        FoundCity(P, StartLoc[P]); // capital
     1783        Founded[P] := 1;
    17831784        with City[0] do
    17841785        begin
    1785           ID := p shl 12;
     1786          ID := P shl 12;
    17861787          Flags := chFounded;
    17871788        end;
     
    17901791  TerritoryCount[nPl] := MapSize;
    17911792  // fillchar(NewContact, sizeof(NewContact), false);
    1792 end; // InitGame
     1793end;
    17931794
    17941795procedure InitRandomGame;
     
    17971798  CalculatePrimitive;
    17981799  CreateElevation;
    1799   CreateMap(false);
     1800  CreateMap(False);
    18001801  StartPositions;
    18011802  InitGame;
    18021803end;
    18031804
    1804 procedure InitMapGame(Human: integer);
     1805procedure InitMapGame(Human: Integer);
    18051806begin
    18061807  DelphiRandSeed := RND;
     
    18121813procedure ReleaseGame;
    18131814var
    1814   p1, p2: integer;
     1815  p1, p2: Integer;
    18151816begin
    18161817  for p1 := 0 to nPl - 1 do
     
    18341835procedure InitMapEditor;
    18351836var
    1836   p1: integer;
     1837  p1: Integer;
    18371838begin
    18381839  CalculatePrimitive;
     
    18711872end;
    18721873
    1873 procedure EditTile(Loc, NewTile: integer);
    1874 var
    1875   Loc1, V21: integer;
     1874procedure EditTile(Loc, NewTile: Integer);
     1875var
     1876  Loc1, V21: Integer;
    18761877  Radius: TVicinity21Loc;
    18771878begin
     
    18971898    if (NewTile and fTerImp = tiIrrigation) or (NewTile and fTerImp = tiFarm)
    18981899    then
    1899       NewTile := NewTile and not fTerImp
     1900      NewTile := NewTile and not fTerImp;
    19001901  end;
    19011902  if (Terrain[NewTile and fTerrain].MineEff = 0) and
     
    19211922      RealMap[Loc1] := RealMap[Loc1] or ($F shl 27);
    19221923      RW[0].Map[Loc1] := RealMap[Loc1] and $07FFFFFF or fObserved;
    1923     end
     1924    end;
    19241925  end;
    19251926  // RealMap[Loc]:=RealMap[Loc] and not fSpecial;
     
    19311932  ____________________________________________________________________
    19321933}
    1933 function GetTileInfo(p, cix, Loc: integer; var Info: TTileInfo): integer;
     1934function GetTileInfo(P, cix, Loc: Integer; var Info: TTileInfo): Integer;
    19341935// cix>=0 - known city index of player p -- only core internal!
    19351936// cix=-1 - search city, player unknown, only if permission for p
    19361937// cix=-2 - don't search city, don't calculate city benefits, just government of player p
    19371938var
    1938   p0, Tile, special: integer;
     1939  p0, Tile, special: Integer;
    19391940begin
    19401941  with Info do
    19411942  begin
    1942     p0 := p;
     1943    p0 := P;
    19431944    if cix >= 0 then
    19441945      Tile := RealMap[Loc]
    19451946    else
    19461947    begin
    1947       Tile := RW[p].Map[Loc];
     1948      Tile := RW[P].Map[Loc];
    19481949      if Tile and fTerrain = fUNKNOWN then
    19491950      begin
    1950         result := eNoPreq;
    1951         exit;
     1951        Result := eNoPreq;
     1952        Exit;
    19521953      end;
    19531954    end;
     
    19551956    if (cix = -1) and (UsedByCity[Loc] >= 0) then
    19561957    begin // search exploiting player and city
    1957       SearchCity(UsedByCity[Loc], p, cix);
    1958       if not((p = p0) or (ObserveLevel[UsedByCity[Loc]] shr (2 * p0) and
     1958      SearchCity(UsedByCity[Loc], P, cix);
     1959      if not((P = p0) or (ObserveLevel[UsedByCity[Loc]] shr (2 * p0) and
    19591960        3 = lObserveSuper)) then
    19601961        cix := -1
     
    19621963    if cix = -1 then
    19631964    begin
    1964       result := eInvalid;
    1965       exit;
     1965      Result := eInvalid;
     1966      Exit;
    19661967    end; // no city found here
    19671968
    1968     special := Tile and fSpecial and ResourceMask[p] shr 5;
     1969    special := Tile and fSpecial and ResourceMask[P] shr 5;
    19691970    with Terrain[Tile and fTerrain] do
    19701971    begin
     
    19731974      Trade := TradeRes[special];
    19741975      if (special > 0) and (Tile and fTerrain <> fGrass) and
    1975         (RW[p].NatBuilt[imSpacePort] > 0) then
     1976        (RW[P].NatBuilt[imSpacePort] > 0) then
    19761977      begin // GeoSat effect
    19771978        Food := 2 * Food - FoodRes[0];
     
    19821983      if (Tile and fTerImp = tiIrrigation) or (Tile and fTerImp = tiFarm) or
    19831984        (Tile and fCity <> 0) then
    1984         inc(Food, IrrEff); { irrigation effect }
     1985        Inc(Food, IrrEff); { irrigation effect }
    19851986      if Tile and fTerImp = tiMine then
    1986         inc(Prod, MineEff); { mining effect }
    1987       if (Tile and fRiver <> 0) and (RW[p].Tech[adMapMaking] >= tsApplicable)
     1987        Inc(Prod, MineEff); { mining effect }
     1988      if (Tile and fRiver <> 0) and (RW[P].Tech[adMapMaking] >= tsApplicable)
    19881989      then
    1989         inc(Trade); { river effect }
     1990        Inc(Trade); { river effect }
    19901991      if (Tile and (fRoad or fRR) <> 0) and (MoveCost = 1) and
    1991         (RW[p].Tech[adWheel] >= tsApplicable) then
    1992         inc(Trade); { road effect }
     1992        (RW[P].Tech[adWheel] >= tsApplicable) then
     1993        Inc(Trade); { road effect }
    19931994      if (Tile and (fRR or fCity) <> 0) and
    1994         (RW[p].Tech[adRailroad] >= tsApplicable) then
    1995         inc(Prod, Prod shr 1); { railroad effect }
     1995        (RW[P].Tech[adRailroad] >= tsApplicable) then
     1996        Inc(Prod, Prod shr 1); { railroad effect }
    19961997
    19971998      ExplCity := -1;
    1998       if (cix >= 0) and (p = p0) then
     1999      if (cix >= 0) and (P = p0) then
    19992000        ExplCity := cix;
    20002001      if cix >= 0 then
     
    20022003        begin
    20032004          if ((Tile and fTerImp = tiFarm) or (Tile and fCity <> 0)) and
    2004             (RW[p].City[cix].Built[imSupermarket] > 0) then
    2005             inc(Food, Food shr 1); { farmland effect }
     2005            (RW[P].City[cix].Built[imSupermarket] > 0) then
     2006            Inc(Food, Food shr 1); { farmland effect }
    20062007          if (Tile and (fRoad or fRR) <> 0) and (MoveCost = 1) and
    2007             (RW[p].City[cix].Built[imHighways] > 0) then
    2008             inc(Trade, 1); { superhighway effect }
     2008            (RW[P].City[cix].Built[imHighways] > 0) then
     2009            Inc(Trade, 1); { superhighway effect }
    20092010        end
    20102011        else
    20112012        begin
    2012           if RW[p].City[cix].Built[imHarbor] > 0 then
    2013             inc(Food); { harbour effect }
    2014           if RW[p].City[cix].Built[imPlatform] > 0 then
    2015             inc(Prod); { oil platform effect }
    2016           if GWonder[woLighthouse].EffectiveOwner = p then
    2017             inc(Prod);
     2013          if RW[P].City[cix].Built[imHarbor] > 0 then
     2014            Inc(Food); { harbour effect }
     2015          if RW[P].City[cix].Built[imPlatform] > 0 then
     2016            Inc(Prod); { oil platform effect }
     2017          if GWonder[woLighthouse].EffectiveOwner = P then
     2018            Inc(Prod);
    20182019        end;
    20192020    end;
    20202021
    20212022    { good government influence }
    2022     if (RW[p].Government in [gRepublic, gDemocracy, gFuture]) and (Trade > 0)
     2023    if (RW[P].Government in [gRepublic, gDemocracy, gFuture]) and (Trade > 0)
    20232024    then
    2024       inc(Trade);
    2025     if (RW[p].Government = gCommunism) and (Prod > 1) then
    2026       inc(Prod);
    2027 
    2028     if RW[p].Government in [gAnarchy, gDespotism] then
     2025      Inc(Trade);
     2026    if (RW[P].Government = gCommunism) and (Prod > 1) then
     2027      Inc(Prod);
     2028
     2029    if RW[P].Government in [gAnarchy, gDespotism] then
    20292030    begin { bad government influence }
    20302031      if Food > 3 then
     
    20382039    if Tile and (fTerrain or fPoll) > fPoll then
    20392040    begin { pollution - decrease ressources }
    2040       dec(Food, Food shr 1);
    2041       dec(Prod, Prod shr 1);
    2042       dec(Trade, Trade shr 1);
     2041      Dec(Food, Food shr 1);
     2042      Dec(Prod, Prod shr 1);
     2043      Dec(Trade, Trade shr 1);
    20432044    end;
    20442045
    20452046    if Tile and fCity <> 0 then
    20462047      Trade := 0
    2047     else if (cix >= 0) and (RW[p].City[cix].Built[imCourt] + RW[p].City[cix]
     2048    else if (cix >= 0) and (RW[P].City[cix].Built[imCourt] + RW[P].City[cix]
    20482049      .Built[imPalace] = 0) then
    2049       if RW[p].City[cix].Built[imTownHall] = 0 then
     2050      if RW[P].City[cix].Built[imTownHall] = 0 then
    20502051        Trade := 0
    20512052      else if Trade > 3 then
    20522053        Trade := 3;
    20532054  end;
    2054   result := eOK;
    2055 end; { GetTileInfo }
    2056 
    2057 procedure Strongest(Loc: integer; var uix, Strength, Bonus, Cnt: integer);
     2055  Result := eOK;
     2056end;
     2057
     2058procedure Strongest(Loc: Integer; var uix, Strength, Bonus, Cnt: Integer);
    20582059{ find strongest defender at Loc }
    20592060var
    20602061  Defender, uix1, Det, Cost, TestStrength, TestBonus, TestDet, TestCost,
    2061     Domain: integer;
     2062    Domain: Integer;
    20622063  PUn: ^TUn;
    20632064  PModel: ^TModel;
     
    20772078    if PUn.Loc = Loc then
    20782079    begin
    2079       inc(Cnt);
     2080      Inc(Cnt);
    20802081      if PUn.Master < 0 then
    20812082      begin
     
    20842085          TestBonus := Terrain[RealMap[Loc] and fTerrain].Defense;
    20852086          if RealMap[Loc] and fTerImp = tiFort then
    2086             inc(TestBonus, 4);
     2087            Inc(TestBonus, 4);
    20872088          if PUn.Flags and unFortified <> 0 then
    2088             inc(TestBonus, 2);
     2089            Inc(TestBonus, 2);
    20892090          if (PModel.Kind = mkSpecial_TownGuard) and
    20902091            (RealMap[Loc] and fCity <> 0) then
    2091             inc(TestBonus, 4);
     2092            Inc(TestBonus, 4);
    20922093        end
    20932094        else
    20942095          TestBonus := 4;
    2095         inc(TestBonus, PUn.exp div ExpCost);
     2096        Inc(TestBonus, PUn.exp div ExpCost);
    20962097        TestStrength := PModel.Defense * TestBonus * PUn.Health;
    20972098        if (Domain = dAir) and ((RealMap[Loc] and fCity <> 0) or
     
    21032104        if PModel.Cap[mcStealth] > 0 then
    21042105        else if PModel.Cap[mcSub] > 0 then
    2105           inc(TestDet, 1 shl 28)
     2106          Inc(TestDet, 1 shl 28)
    21062107        else if (Domain = dGround) and (PModel.Cap[mcFanatic] > 0) and
    21072108          not(RW[Defender].Government in [gRepublic, gDemocracy, gFuture]) then
    2108           inc(TestDet, 4 shl 28) // fanatic ground units always defend
     2109          Inc(TestDet, 4 shl 28) // fanatic ground units always defend
    21092110        else if PModel.Flags and mdZOC <> 0 then
    2110           inc(TestDet, 3 shl 28)
     2111          Inc(TestDet, 3 shl 28)
    21112112        else
    2112           inc(TestDet, 2 shl 28);
     2113          Inc(TestDet, 2 shl 28);
    21132114        TestCost := RW[Defender].Model[PUn.mix].Cost;
    21142115        if (TestDet > Det) or (TestDet = Det) and (TestCost < Cost) then
     
    21252126end;
    21262127
    2127 function UnitSpeed(p, mix, Health: integer): integer;
    2128 begin
    2129   with RW[p].Model[mix] do
    2130   begin
    2131     result := Speed;
     2128function UnitSpeed(P, mix, Health: Integer): Integer;
     2129begin
     2130  with RW[P].Model[mix] do
     2131  begin
     2132    Result := Speed;
    21322133    if Domain = dSea then
    21332134    begin
    2134       if GWonder[woMagellan].EffectiveOwner = p then
    2135         inc(result, 200);
     2135      if GWonder[woMagellan].EffectiveOwner = P then
     2136        Inc(Result, 200);
    21362137      if Health < 100 then
    2137         result := ((result - 250) * Health div 5000) * 50 + 250;
    2138     end
    2139   end
    2140 end;
    2141 
    2142 procedure GetUnitReport(p, uix: integer; var UnitReport: TUnitReport);
    2143 var
    2144   TerrOwner: integer;
     2138        Result := ((Result - 250) * Health div 5000) * 50 + 250;
     2139    end;
     2140  end;
     2141end;
     2142
     2143procedure GetUnitReport(P, uix: Integer; var UnitReport: TUnitReport);
     2144var
     2145  TerrOwner: Integer;
    21452146  PModel: ^TModel;
    21462147begin
     
    21482149  UnitReport.ProdSupport := 0;
    21492150  UnitReport.ReportFlags := 0;
    2150   if RW[p].Government <> gAnarchy then
    2151     with RW[p].Un[uix] do
    2152     begin
    2153       PModel := @RW[p].Model[mix];
     2151  if RW[P].Government <> gAnarchy then
     2152    with RW[P].Un[uix] do
     2153    begin
     2154      PModel := @RW[P].Model[mix];
    21542155      if (PModel.Kind = mkSettler)
    21552156      { and (GWonder[woFreeSettlers].EffectiveOwner<>p) } then
    2156         UnitReport.FoodSupport := SettlerFood[RW[p].Government]
     2157        UnitReport.FoodSupport := SettlerFood[RW[P].Government]
    21572158      else if Flags and unConscripts <> 0 then
    21582159        UnitReport.FoodSupport := 1;
    21592160
    2160       if RW[p].Government <> gFundamentalism then
     2161      if RW[P].Government <> gFundamentalism then
    21612162      begin
    21622163        if GTestFlags and tfImmImprove = 0 then
     
    21732174        begin
    21742175          TerrOwner := RealMap[Loc] shr 27;
    2175           case RW[p].Government of
     2176          case RW[P].Government of
    21762177            gRepublic, gFuture:
    2177               if (TerrOwner <> p) and (TerrOwner < nPl) and
    2178                 (RW[p].Treaty[TerrOwner] < trAlliance) then
     2178              if (TerrOwner <> P) and (TerrOwner < nPl) and
     2179                (RW[P].Treaty[TerrOwner] < trAlliance) then
    21792180                UnitReport.ReportFlags := UnitReport.ReportFlags or urfDeployed;
    21802181            gDemocracy:
    2181               if (TerrOwner >= nPl) or (TerrOwner <> p) and
    2182                 (RW[p].Treaty[TerrOwner] < trAlliance) then
     2182              if (TerrOwner >= nPl) or (TerrOwner <> P) and
     2183                (RW[P].Treaty[TerrOwner] < trAlliance) then
    21832184                UnitReport.ReportFlags := UnitReport.ReportFlags or urfDeployed;
    21842185          end;
     
    21882189end;
    21892190
    2190 procedure SearchCity(Loc: integer; var p, cix: integer);
     2191procedure SearchCity(Loc: Integer; var P, cix: Integer);
    21912192// set p to supposed owner before call
    21922193var
    2193   i: integer;
     2194  I: Integer;
    21942195begin
    21952196  if RealMap[Loc] < nPl shl 27 then
    2196     p := RealMap[Loc] shr 27;
    2197   for i := 0 to nPl - 1 do
    2198   begin
    2199     if 1 shl p and GAlive <> 0 then
    2200       with RW[p] do
     2197    P := RealMap[Loc] shr 27;
     2198  for I := 0 to nPl - 1 do
     2199  begin
     2200    if 1 shl P and GAlive <> 0 then
     2201      with RW[P] do
    22012202      begin
    22022203        cix := nCity - 1;
    22032204        while (cix >= 0) and (City[cix].Loc <> Loc) do
    2204           dec(cix);
     2205          Dec(cix);
    22052206        if cix >= 0 then
    2206           exit;
    2207       end;
    2208     assert(i < nPl - 1);
    2209     p := (p + 1) mod nPl;
    2210   end;
    2211 end;
    2212 
    2213 procedure MakeCityInfo(p, cix: integer; var ci: TCityInfo);
    2214 begin
    2215   assert((p >= 0) and (p < nPl));
    2216   assert((cix >= 0) and (cix < RW[p].nCity));
    2217   with RW[p].City[cix] do
     2207          Exit;
     2208      end;
     2209    Assert(I < nPl - 1);
     2210    P := (P + 1) mod nPl;
     2211  end;
     2212end;
     2213
     2214procedure MakeCityInfo(P, cix: Integer; var ci: TCityInfo);
     2215begin
     2216  Assert((P >= 0) and (P < nPl));
     2217  Assert((cix >= 0) and (cix < RW[P].nCity));
     2218  with RW[P].City[cix] do
    22182219  begin
    22192220    ci.Loc := Loc;
    22202221    ci.ID := ID;
    2221     ci.Owner := p;
     2222    ci.Owner := P;
    22222223    ci.Size := Size;
    22232224    ci.Flags := 0;
    22242225    if Built[imPalace] > 0 then
    2225       inc(ci.Flags, ciCapital);
    2226     if (Built[imWalls] > 0) or (Continent[Loc] = GrWallContinent[p]) then
    2227       inc(ci.Flags, ciWalled);
     2226      Inc(ci.Flags, ciCapital);
     2227    if (Built[imWalls] > 0) or (Continent[Loc] = GrWallContinent[P]) then
     2228      Inc(ci.Flags, ciWalled);
    22282229    if Built[imCoastalFort] > 0 then
    2229       inc(ci.Flags, ciCoastalFort);
     2230      Inc(ci.Flags, ciCoastalFort);
    22302231    if Built[imMissileBat] > 0 then
    2231       inc(ci.Flags, ciMissileBat);
     2232      Inc(ci.Flags, ciMissileBat);
    22322233    if Built[imBunker] > 0 then
    2233       inc(ci.Flags, ciBunker);
     2234      Inc(ci.Flags, ciBunker);
    22342235    if Built[imSpacePort] > 0 then
    2235       inc(ci.Flags, ciSpacePort);
    2236   end;
    2237 end;
    2238 
    2239 procedure TellAboutModel(p, taOwner, tamix: integer);
    2240 var
    2241   i: integer;
    2242 begin
    2243   if (p = taOwner) or (Mode < moPlaying) then
    2244     exit;
    2245   i := 0;
    2246   while (i < RW[p].nEnemyModel) and ((RW[p].EnemyModel[i].Owner <> taOwner) or
    2247     (RW[p].EnemyModel[i].mix <> tamix)) do
    2248     inc(i);
    2249   if i = RW[p].nEnemyModel then
    2250     IntServer(sIntTellAboutModel + p shl 4, taOwner, tamix, nil^);
    2251 end;
    2252 
    2253 function emixSafe(p, taOwner, tamix: integer): integer;
    2254 begin
    2255   result := RWemix[p, taOwner, tamix];
    2256   if result < 0 then
     2236      Inc(ci.Flags, ciSpacePort);
     2237  end;
     2238end;
     2239
     2240procedure TellAboutModel(P, taOwner, tamix: Integer);
     2241var
     2242  I: Integer;
     2243begin
     2244  if (P = taOwner) or (Mode < moPlaying) then
     2245    Exit;
     2246  I := 0;
     2247  while (I < RW[P].nEnemyModel) and ((RW[P].EnemyModel[I].Owner <> taOwner) or
     2248    (RW[P].EnemyModel[I].mix <> tamix)) do
     2249    Inc(I);
     2250  if I = RW[P].nEnemyModel then
     2251    IntServer(sIntTellAboutModel + P shl 4, taOwner, tamix, nil^);
     2252end;
     2253
     2254function emixSafe(P, taOwner, tamix: Integer): Integer;
     2255begin
     2256  Result := RWemix[P, taOwner, tamix];
     2257  if Result < 0 then
    22572258  begin // sIntTellAboutModel comes too late
    2258     assert(Mode = moMovie);
    2259     result := $FFFF;
    2260   end;
    2261 end;
    2262 
    2263 procedure IntroduceEnemy(p1, p2: integer);
     2259    Assert(Mode = moMovie);
     2260    Result := $FFFF;
     2261  end;
     2262end;
     2263
     2264procedure IntroduceEnemy(p1, p2: Integer);
    22642265begin
    22652266  RW[p1].Treaty[p2] := trNone;
     
    22672268end;
    22682269
    2269 function DiscoverTile(Loc, p, pTell, Level: integer; EnableContact: boolean;
    2270   euix: integer = -2): boolean;
     2270function DiscoverTile(Loc, P, pTell, Level: Integer; EnableContact: Boolean;
     2271  euix: Integer = -2): Boolean;
    22712272// euix = -2: full discover
    22722273// euix = -1: unit and city only, append units in EnemyUn
    22732274// euix >= 0: unit and city only, replace EnemyUn[euix]
    22742275
    2275   procedure SetContact(p1, p2: integer);
     2276  procedure SetContact(p1, p2: Integer);
    22762277  begin
    22772278    if (Mode < moPlaying) or (p1 = p2) or (RW[p1].Treaty[p2] > trNoContact) then
    2278       exit;
     2279      Exit;
    22792280    IntServer(sIntTellAboutNation, p1, p2, nil^);
    22802281    // NewContact[p1,p2]:=true
     
    22822283
    22832284var
    2284   i, uix, cix, TerrOwner, TerrOwnerTreaty, Strength, Bonus, Cnt, pFoundCity,
    2285     cixFoundCity, MinLevel, Loc1, V8: integer;
     2285  I, uix, cix, TerrOwner, TerrOwnerTreaty, Strength, Bonus, Cnt, pFoundCity,
     2286    cixFoundCity, MinLevel, Loc1, V8: Integer;
    22862287  Tile, AddFlags: Cardinal;
    22872288  Adjacent: TVicinity8Loc;
     
    22892290  mox: ^TModel;
    22902291begin
    2291   result := false;
     2292  Result := False;
    22922293  with RW[pTell] do
    22932294  begin
     
    23052306        AddFlags := AddFlags or fGrWall;
    23062307      if (Mode = moPlaying) and ((Tile and (nPl shl 27) <> nPl shl 27) and
    2307         (pTell = p)) then
     2308        (pTell = P)) then
    23082309      begin // set fPeace flag?
    23092310        TerrOwner := Tile shr 27;
     
    23142315            (1 shl trPeace or 1 shl TrFriendlyContact) <> 0 then
    23152316            AddFlags := AddFlags or fPeace;
    2316         end
     2317        end;
    23172318      end;
    23182319
     
    23322333          unx := @RW[Occupant[Loc]].Un[uix];
    23332334          mox := @RW[Occupant[Loc]].Model[unx.mix];
    2334           assert((ZoCMap[Loc] <> 0) = (mox.Flags and mdZOC <> 0));
     2335          Assert((ZoCMap[Loc] <> 0) = (mox.Flags and mdZOC <> 0));
    23352336          if (mox.Cap[mcStealth] > 0) and (Tile and fCity = 0) and
    23362337            (Tile and fTerImp <> tiBase) then
     
    23482349            begin
    23492350              uix := nEnemyUn;
    2350               inc(nEnemyUn);
    2351               assert(nEnemyUn < neumax);
     2351              Inc(nEnemyUn);
     2352              Assert(nEnemyUn < neumax);
    23522353            end;
    23532354            MakeUnitInfo(Occupant[Loc], unx^, EnemyUn[uix]);
    23542355            if Cnt > 1 then
    23552356              EnemyUn[uix].Flags := EnemyUn[uix].Flags or unMulti;
    2356             if (mox.Flags and mdZOC <> 0) and (pTell = p) and
     2357            if (mox.Flags and mdZOC <> 0) and (pTell = P) and
    23572358              (Treaty[Occupant[Loc]] < trAlliance) then
    23582359            begin // set fInEnemyZoC flags of surrounding tiles
     
    23632364                if (Loc1 >= 0) and (Loc1 < MapSize) then
    23642365                  Map[Loc1] := Map[Loc1] or fInEnemyZoC
    2365               end
     2366              end;
    23662367            end;
    23672368            if EnableContact and (mox.Domain = dGround) then
     
    23732374            end;
    23742375            // Level:=lObserveSuper; // don't discover unit twice
    2375             if (pTell = p) and
     2376            if (pTell = P) and
    23762377              ((Tile and fCity = 0) or (1 shl pTell and GAI <> 0)) then
    2377               result := true;
     2378              Result := True;
    23782379          end
    23792380          else
     
    23972398          while (cixFoundCity >= 0) and
    23982399            (RW[pFoundCity].City[cixFoundCity].Loc <> Loc) do
    2399             dec(cixFoundCity);
    2400           assert(cixFoundCity >= 0);
    2401           i := 0;
    2402           while (i < nEnemyCity) and (EnemyCity[i].Loc <> Loc) do
    2403             inc(i);
    2404           if i = nEnemyCity then
     2400            Dec(cixFoundCity);
     2401          Assert(cixFoundCity >= 0);
     2402          I := 0;
     2403          while (I < nEnemyCity) and (EnemyCity[I].Loc <> Loc) do
     2404            Inc(I);
     2405          if I = nEnemyCity then
    24052406          begin
    2406             inc(nEnemyCity);
    2407             assert(nEnemyCity < necmax);
    2408             EnemyCity[i].Status := 0;
    2409             EnemyCity[i].SavedStatus := 0;
    2410             if pTell = p then
    2411               result := true;
     2407            Inc(nEnemyCity);
     2408            Assert(nEnemyCity < necmax);
     2409            EnemyCity[I].Status := 0;
     2410            EnemyCity[I].SavedStatus := 0;
     2411            if pTell = P then
     2412              Result := True;
    24122413          end;
    2413           MakeCityInfo(pFoundCity, cixFoundCity, EnemyCity[i]);
     2414          MakeCityInfo(pFoundCity, cixFoundCity, EnemyCity[I]);
    24142415        end;
    24152416      end
     
    24202421
    24212422    if Map[Loc] and fTerrain = fUNKNOWN then
    2422       inc(Discovered[pTell]);
     2423      Inc(Discovered[pTell]);
    24232424    if euix >= -1 then
    24242425      Map[Loc] := Map[Loc] and not(fUnit or fCity or fOwned or fOwnZoCUnit) or
     
    24372438      Cardinal(Level) shl (2 * pTell);
    24382439  end;
    2439 end; // DiscoverTile
    2440 
    2441 function Discover9(Loc, p, Level: integer;
    2442   TellAllied, EnableContact: boolean): boolean;
    2443 var
    2444   V9, Loc1, pTell, OldLevel: integer;
     2440end;
     2441
     2442function Discover9(Loc, P, Level: Integer;
     2443  TellAllied, EnableContact: Boolean): Boolean;
     2444var
     2445  V9, Loc1, pTell, OldLevel: Integer;
    24452446  Radius: TVicinity8Loc;
    24462447begin
    2447   assert((Mode > moLoading_Fast) or (RW[p].nEnemyUn = 0));
    2448   result := false;
     2448  Assert((Mode > moLoading_Fast) or (RW[P].nEnemyUn = 0));
     2449  Result := False;
    24492450  V8_to_Loc(Loc, Radius);
    24502451  for V9 := 0 to 8 do
     
    24582459      begin
    24592460        for pTell := 0 to nPl - 1 do
    2460           if (pTell = p) or (1 shl pTell and GAlive <> 0) and
    2461             (RW[p].Treaty[pTell] = trAlliance) then
     2461          if (pTell = P) or (1 shl pTell and GAlive <> 0) and
     2462            (RW[P].Treaty[pTell] = trAlliance) then
    24622463          begin
    24632464            OldLevel := ObserveLevel[Loc1] shr (2 * pTell) and 3;
    24642465            if Level > OldLevel then
    2465               result := DiscoverTile(Loc1, p, pTell, Level, EnableContact)
    2466                 or result;
     2466              Result := DiscoverTile(Loc1, P, pTell, Level, EnableContact)
     2467                or Result;
    24672468          end;
    24682469      end
    24692470      else
    24702471      begin
    2471         OldLevel := ObserveLevel[Loc1] shr (2 * p) and 3;
     2472        OldLevel := ObserveLevel[Loc1] shr (2 * P) and 3;
    24722473        if Level > OldLevel then
    2473           result := DiscoverTile(Loc1, p, p, Level, EnableContact) or result;
    2474       end;
    2475   end;
    2476 end;
    2477 
    2478 function Discover21(Loc, p, AdjacentLevel: integer;
    2479   TellAllied, EnableContact: boolean): boolean;
    2480 var
    2481   V21, Loc1, pTell, Level, OldLevel, AdjacentFlags: integer;
     2474          Result := DiscoverTile(Loc1, P, P, Level, EnableContact) or Result;
     2475      end;
     2476  end;
     2477end;
     2478
     2479function Discover21(Loc, P, AdjacentLevel: Integer;
     2480  TellAllied, EnableContact: Boolean): Boolean;
     2481var
     2482  V21, Loc1, pTell, Level, OldLevel, AdjacentFlags: Integer;
    24822483  Radius: TVicinity21Loc;
    24832484begin
    2484   assert((Mode > moLoading_Fast) or (RW[p].nEnemyUn = 0));
    2485   result := false;
     2485  Assert((Mode > moLoading_Fast) or (RW[P].nEnemyUn = 0));
     2486  Result := False;
    24862487  AdjacentFlags := $00267620 shr 1;
    24872488  V21_to_Loc(Loc, Radius);
     
    24982499      begin
    24992500        for pTell := 0 to nPl - 1 do
    2500           if (pTell = p) or (1 shl pTell and GAlive <> 0) and
    2501             (RW[p].Treaty[pTell] = trAlliance) then
     2501          if (pTell = P) or (1 shl pTell and GAlive <> 0) and
     2502            (RW[P].Treaty[pTell] = trAlliance) then
    25022503          begin
    25032504            OldLevel := ObserveLevel[Loc1] shr (2 * pTell) and 3;
    25042505            if Level > OldLevel then
    2505               result := DiscoverTile(Loc1, p, pTell, Level, EnableContact)
    2506                 or result;
     2506              Result := DiscoverTile(Loc1, P, pTell, Level, EnableContact)
     2507                or Result;
    25072508          end;
    25082509      end
    25092510      else
    25102511      begin
    2511         OldLevel := ObserveLevel[Loc1] shr (2 * p) and 3;
     2512        OldLevel := ObserveLevel[Loc1] shr (2 * P) and 3;
    25122513        if Level > OldLevel then
    2513           result := DiscoverTile(Loc1, p, p, Level, EnableContact) or result;
     2514          Result := DiscoverTile(Loc1, P, P, Level, EnableContact) or Result;
    25142515      end;
    25152516    end;
     
    25182519end;
    25192520
    2520 procedure DiscoverAll(p, Level: integer);
     2521procedure DiscoverAll(P, Level: Integer);
    25212522{ player p discovers complete playground (for supervisor) }
    25222523var
    2523   Loc, OldLevel: integer;
    2524 begin
    2525   assert((Mode > moLoading_Fast) or (RW[p].nEnemyUn = 0));
     2524  Loc, OldLevel: Integer;
     2525begin
     2526  Assert((Mode > moLoading_Fast) or (RW[P].nEnemyUn = 0));
    25262527  for Loc := 0 to MapSize - 1 do
    25272528  begin
    2528     OldLevel := ObserveLevel[Loc] shr (2 * p) and 3;
     2529    OldLevel := ObserveLevel[Loc] shr (2 * P) and 3;
    25292530    if Level > OldLevel then
    2530       DiscoverTile(Loc, p, p, Level, false);
    2531   end;
    2532 end;
    2533 
    2534 procedure DiscoverViewAreas(p: integer);
    2535 var
    2536   pTell, uix, cix, ecix, Loc, RealOwner: integer;
     2531      DiscoverTile(Loc, P, P, Level, False);
     2532  end;
     2533end;
     2534
     2535procedure DiscoverViewAreas(P: Integer);
     2536var
     2537  pTell, uix, cix, ecix, Loc, RealOwner: Integer;
    25372538  PModel: ^TModel;
    25382539begin // discover unit and city view areas
    25392540  for pTell := 0 to nPl - 1 do
    2540     if (pTell = p) or (RW[p].Treaty[pTell] = trAlliance) then
     2541    if (pTell = P) or (RW[P].Treaty[pTell] = trAlliance) then
    25412542    begin
    25422543      for uix := 0 to RW[pTell].nUn - 1 do
     
    25462547            PModel := @RW[pTell].Model[mix];
    25472548            if (PModel.Kind = mkDiplomat) or (PModel.Cap[mcSpy] > 0) then
    2548               Discover21(Loc, p, lObserveSuper, false, true)
     2549              Discover21(Loc, P, lObserveSuper, False, True)
    25492550            else if (PModel.Cap[mcRadar] + PModel.Cap[mcCarrier] > 0) or
    25502551              (PModel.Domain = dAir) then
    2551               Discover21(Loc, p, lObserveAll, false, false)
     2552              Discover21(Loc, P, lObserveAll, False, False)
    25522553            else if (RealMap[Loc] and fTerrain = fMountains) or
    25532554              (RealMap[Loc] and fTerImp = tiFort) or
    25542555              (RealMap[Loc] and fTerImp = tiBase) or (PModel.Cap[mcAcademy] > 0)
    25552556            then
    2556               Discover21(Loc, p, lObserveUnhidden, false,
     2557              Discover21(Loc, P, lObserveUnhidden, False,
    25572558                PModel.Domain = dGround)
    25582559            else
    2559               Discover9(Loc, p, lObserveUnhidden, false,
     2560              Discover9(Loc, P, lObserveUnhidden, False,
    25602561                PModel.Domain = dGround);
    25612562          end;
    25622563      for cix := 0 to RW[pTell].nCity - 1 do
    25632564        if RW[pTell].City[cix].Loc >= 0 then
    2564           Discover21(RW[pTell].City[cix].Loc, p, lObserveUnhidden, false, true);
     2565          Discover21(RW[pTell].City[cix].Loc, P, lObserveUnhidden, False, True);
    25652566      for ecix := 0 to RW[pTell].nEnemyCity - 1 do
    25662567      begin // players know territory, so no use in hiding city owner
     
    25742575          begin
    25752576            RW[pTell].EnemyCity[ecix].Loc := -1;
    2576             RW[pTell].Map[Loc] := RW[pTell].Map[Loc] and not fCity
     2577            RW[pTell].Map[Loc] := RW[pTell].Map[Loc] and not fCity;
    25772578          end;
    25782579        end;
     
    25812582end;
    25822583
    2583 function GetUnitStack(p, Loc: integer): integer;
    2584 var
    2585   uix: integer;
     2584function GetUnitStack(P, Loc: Integer): Integer;
     2585var
     2586  uix: Integer;
    25862587  unx: ^TUn;
    25872588begin
    2588   result := 0;
     2589  Result := 0;
    25892590  if Occupant[Loc] < 0 then
    2590     exit;
     2591    Exit;
    25912592  for uix := 0 to RW[Occupant[Loc]].nUn - 1 do
    25922593  begin
     
    25942595    if unx.Loc = Loc then
    25952596    begin
    2596       MakeUnitInfo(Occupant[Loc], unx^, RW[p].EnemyUn[RW[p].nEnemyUn + result]);
    2597       TellAboutModel(p, Occupant[Loc], unx.mix);
    2598       RW[p].EnemyUn[RW[p].nEnemyUn + result].emix :=
    2599         RWemix[p, Occupant[Loc], unx.mix];
    2600       inc(result);
    2601     end;
    2602   end;
    2603 end;
    2604 
    2605 procedure UpdateUnitMap(Loc: integer; CityChange: boolean = false);
     2597      MakeUnitInfo(Occupant[Loc], unx^, RW[P].EnemyUn[RW[P].nEnemyUn + Result]);
     2598      TellAboutModel(P, Occupant[Loc], unx.mix);
     2599      RW[P].EnemyUn[RW[P].nEnemyUn + Result].emix :=
     2600        RWemix[P, Occupant[Loc], unx.mix];
     2601      Inc(Result);
     2602    end;
     2603  end;
     2604end;
     2605
     2606procedure UpdateUnitMap(Loc: Integer; CityChange: Boolean = False);
    26062607// update maps and enemy units of all players after unit change
    26072608var
    2608   p, euix, OldLevel: integer;
     2609  P, euix, OldLevel: Integer;
    26092610  AddFlags, ClearFlags: Cardinal;
    26102611begin
    26112612  if (Mode = moLoading_Fast) and not CityChange then
    2612     exit;
    2613   for p := 0 to nPl - 1 do
    2614     if 1 shl p and (GAlive or GWatching) <> 0 then
    2615     begin
    2616       OldLevel := ObserveLevel[Loc] shr (2 * p) and 3;
     2613    Exit;
     2614  for P := 0 to nPl - 1 do
     2615    if 1 shl P and (GAlive or GWatching) <> 0 then
     2616    begin
     2617      OldLevel := ObserveLevel[Loc] shr (2 * P) and 3;
    26172618      if OldLevel > lNoObserve then
    26182619      begin
    2619         if RW[p].Map[Loc] and (fUnit or fOwned) = fUnit then
     2620        if RW[P].Map[Loc] and (fUnit or fOwned) = fUnit then
    26202621        begin
    26212622          // replace unit located here in EnemyUn
    26222623          // do not just set loc:=-1 because total number would be unlimited
    2623           euix := RW[p].nEnemyUn - 1;
     2624          euix := RW[P].nEnemyUn - 1;
    26242625          while euix >= 0 do
    26252626          begin
    2626             if RW[p].EnemyUn[euix].Loc = Loc then
     2627            if RW[P].EnemyUn[euix].Loc = Loc then
    26272628            begin
    2628               RW[p].EnemyUn[euix].Loc := -1;
     2629              RW[P].EnemyUn[euix].Loc := -1;
    26292630              Break;
    26302631            end;
    2631             dec(euix);
     2632            Dec(euix);
    26322633          end;
    2633           RW[p].Map[Loc] := RW[p].Map[Loc] and not fUnit
     2634          RW[P].Map[Loc] := RW[P].Map[Loc] and not fUnit
    26342635        end
    26352636        else
    26362637        begin // look for empty slot in EnemyUn
    2637           euix := RW[p].nEnemyUn - 1;
    2638           while (euix >= 0) and (RW[p].EnemyUn[euix].Loc >= 0) do
    2639             dec(euix);
     2638          euix := RW[P].nEnemyUn - 1;
     2639          while (euix >= 0) and (RW[P].EnemyUn[euix].Loc >= 0) do
     2640            Dec(euix);
    26402641        end;
    26412642        if (Occupant[Loc] < 0) and not CityChange then
     
    26442645          if RealMap[Loc] and fCity = 0 then
    26452646            ClearFlags := ClearFlags or fOwned;
    2646           RW[p].Map[Loc] := RW[p].Map[Loc] and not ClearFlags;
     2647          RW[P].Map[Loc] := RW[P].Map[Loc] and not ClearFlags;
    26472648        end
    2648         else if (Occupant[Loc] <> p) or CityChange then
     2649        else if (Occupant[Loc] <> P) or CityChange then
    26492650        begin // city or enemy unit update necessary, call DiscoverTile
    2650           ObserveLevel[Loc] := ObserveLevel[Loc] and not(3 shl (2 * p));
    2651           DiscoverTile(Loc, p, p, OldLevel, false, euix);
     2651          ObserveLevel[Loc] := ObserveLevel[Loc] and not(3 shl (2 * P));
     2652          DiscoverTile(Loc, P, P, OldLevel, False, euix);
    26522653        end
    26532654        else { if (Occupant[Loc]=p) and not CityChange then }
     
    26592660          else
    26602661            ClearFlags := ClearFlags or fOwnZoCUnit;
    2661           RW[p].Map[Loc] := RW[p].Map[Loc] and not ClearFlags or AddFlags;
    2662         end;
    2663       end;
    2664     end;
    2665 end;
    2666 
    2667 procedure RecalcV8ZoC(p, Loc: integer);
     2662          RW[P].Map[Loc] := RW[P].Map[Loc] and not ClearFlags or AddFlags;
     2663        end;
     2664      end;
     2665    end;
     2666end;
     2667
     2668procedure RecalcV8ZoC(P, Loc: Integer);
    26682669// recalculate fInEnemyZoC flags around single tile
    26692670var
    2670   V8, V8V8, Loc1, Loc2, p1, ObserveMask: integer;
     2671  V8, V8V8, Loc1, Loc2, p1, ObserveMask: Integer;
    26712672  Tile1: ^Cardinal;
    26722673  Adjacent, AdjacentAdjacent: TVicinity8Loc;
    26732674begin
    26742675  if Mode = moLoading_Fast then
    2675     exit;
    2676   ObserveMask := 3 shl (2 * p);
     2676    Exit;
     2677  ObserveMask := 3 shl (2 * P);
    26772678  V8_to_Loc(Loc, Adjacent);
    26782679  for V8 := 0 to 7 do
     
    26812682    if (Loc1 >= 0) and (Loc1 < MapSize) then
    26822683    begin
    2683       Tile1 := @RW[p].Map[Loc1];
     2684      Tile1 := @RW[P].Map[Loc1];
    26842685      Tile1^ := Tile1^ and not fInEnemyZoC;
    26852686      V8_to_Loc(Loc1, AdjacentAdjacent);
     
    26912692        begin
    26922693          p1 := Occupant[Loc2];
    2693           assert(p1 <> nPl);
    2694           if (p1 <> p) and (RW[p].Treaty[p1] < trAlliance) then
     2694          Assert(p1 <> nPl);
     2695          if (p1 <> P) and (RW[P].Treaty[p1] < trAlliance) then
    26952696          begin
    26962697            Tile1^ := Tile1^ or fInEnemyZoC;
    2697             Break
     2698            Break;
    26982699          end;
    26992700        end;
     
    27032704end;
    27042705
    2705 procedure RecalcMapZoC(p: integer);
     2706procedure RecalcMapZoC(P: Integer);
    27062707// recalculate fInEnemyZoC flags for the whole map
    27072708var
    2708   Loc, Loc1, V8, p1, ObserveMask: integer;
     2709  Loc, Loc1, V8, p1, ObserveMask: Integer;
    27092710  Adjacent: TVicinity8Loc;
    27102711begin
    27112712  if Mode = moLoading_Fast then
    2712     exit;
    2713   MaskD(RW[p].Map^, MapSize, Cardinal(not Cardinal(fInEnemyZoC)));
    2714   ObserveMask := 3 shl (2 * p);
     2713    Exit;
     2714  MaskD(RW[P].Map^, MapSize, Cardinal(not Cardinal(fInEnemyZoC)));
     2715  ObserveMask := 3 shl (2 * P);
    27152716  for Loc := 0 to MapSize - 1 do
    27162717    if (ZoCMap[Loc] > 0) and (ObserveLevel[Loc] and ObserveMask <> 0) then
    27172718    begin
    27182719      p1 := Occupant[Loc];
    2719       assert(p1 <> nPl);
    2720       if (p1 <> p) and (RW[p].Treaty[p1] < trAlliance) then
     2720      Assert(p1 <> nPl);
     2721      if (p1 <> P) and (RW[P].Treaty[p1] < trAlliance) then
    27212722      begin // this non-allied enemy ZoC unit is known to this player -- set flags!
    27222723        V8_to_Loc(Loc, Adjacent);
     
    27252726          Loc1 := Adjacent[V8];
    27262727          if (Loc1 >= 0) and (Loc1 < MapSize) then
    2727             RW[p].Map[Loc1] := RW[p].Map[Loc1] or fInEnemyZoC
    2728         end;
    2729       end;
    2730     end;
    2731 end;
    2732 
    2733 procedure RecalcPeaceMap(p: integer);
     2728            RW[P].Map[Loc1] := RW[P].Map[Loc1] or fInEnemyZoC;
     2729        end;
     2730      end;
     2731    end;
     2732end;
     2733
     2734procedure RecalcPeaceMap(P: Integer);
    27342735// recalculate fPeace flags for the whole map
    27352736var
    2736   Loc, p1: integer;
    2737   PeacePlayer: array [-1 .. nPl - 1] of boolean;
     2737  Loc, p1: Integer;
     2738  PeacePlayer: array [-1 .. nPl - 1] of Boolean;
    27382739begin
    27392740  if Mode <> moPlaying then
    2740     exit;
    2741   MaskD(RW[p].Map^, MapSize, Cardinal(not Cardinal(fPeace)));
     2741    Exit;
     2742  MaskD(RW[P].Map^, MapSize, Cardinal(not Cardinal(fPeace)));
    27422743  for p1 := -1 to nPl - 1 do
    2743     PeacePlayer[p1] := (p1 >= 0) and (p1 <> p) and (1 shl p1 and GAlive <> 0)
    2744       and (RW[p].Treaty[p1] in [trPeace, TrFriendlyContact]);
     2744    PeacePlayer[p1] := (p1 >= 0) and (p1 <> P) and (1 shl p1 and GAlive <> 0)
     2745      and (RW[P].Treaty[p1] in [trPeace, TrFriendlyContact]);
    27452746  for Loc := 0 to MapSize - 1 do
    2746     if PeacePlayer[RW[p].Territory[Loc]] then
    2747       RW[p].Map[Loc] := RW[p].Map[Loc] or fPeace;
     2747    if PeacePlayer[RW[P].Territory[Loc]] then
     2748      RW[P].Map[Loc] := RW[P].Map[Loc] or fPeace;
    27482749end;
    27492750
     
    27552756  BorderChanges: array [0 .. sIntExpandTerritory and $F - 1] of Cardinal;
    27562757
    2757 procedure ChangeTerritory(Loc, p: integer);
    2758 var
    2759   p1: integer;
    2760 begin
    2761   Assert(p >= 0); // no player's territory indicated by p=nPl
     2758procedure ChangeTerritory(Loc, P: Integer);
     2759var
     2760  p1: Integer;
     2761begin
     2762  Assert(P >= 0); // no player's territory indicated by p=nPl
    27622763  Dec(TerritoryCount[RealMap[Loc] shr 27]);
    2763   Inc(TerritoryCount[p]);
    2764   RealMap[Loc] := RealMap[Loc] and not($F shl 27) or Cardinal(p) shl 27;
    2765   if p = $F then
    2766     p := -1;
     2764  Inc(TerritoryCount[P]);
     2765  RealMap[Loc] := RealMap[Loc] and not($F shl 27) or Cardinal(P) shl 27;
     2766  if P = $F then
     2767    P := -1;
    27672768  for p1 := 0 to nPl - 1 do
    27682769    if 1 shl p1 and (GAlive or GWatching) <> 0 then
    27692770      if RW[p1].Map[Loc] and fTerrain <> fUNKNOWN then
    27702771      begin
    2771         RW[p1].Territory[Loc] := p;
    2772         if (p < nPl) and (p <> p1) and (1 shl p and GAlive <> 0) and
    2773           (RW[p1].Treaty[p] in [trPeace, TrFriendlyContact]) then
     2772        RW[p1].Territory[Loc] := P;
     2773        if (P < nPl) and (P <> p1) and (1 shl P and GAlive <> 0) and
     2774          (RW[p1].Treaty[P] in [trPeace, TrFriendlyContact]) then
    27742775          RW[p1].Map[Loc] := RW[p1].Map[Loc] or fPeace
    27752776        else
     
    27782779end;
    27792780
    2780 procedure ExpandTerritory(OriginLoc: integer);
    2781 var
    2782   i, dx, dy, dxMax, dyMax, Loc, NewOwner: integer;
     2781procedure ExpandTerritory(OriginLoc: Integer);
     2782var
     2783  I, dx, dy, dxMax, dyMax, Loc, NewOwner: Integer;
    27832784begin
    27842785  if OriginLoc = -1 then
    27852786    raise Exception.Create('Location error');
    2786   i := 0;
     2787  I := 0;
    27872788  dyMax := 0;
    27882789  while (dyMax + 1) + (dyMax + 1) shr 1 <= CountryRadius do
    2789     inc(dyMax);
     2790    Inc(dyMax);
    27902791  for dy := -dyMax to dyMax do
    27912792  begin
     
    27932794    while abs(dy) + (dxMax + 2) + abs(abs(dy) - (dxMax + 2)) shr 1 <=
    27942795      CountryRadius do
    2795       inc(dxMax, 2);
     2796      Inc(dxMax, 2);
    27962797    for dx := -dxMax to dxMax do
    27972798      if (dy + dx) and 1 = 0 then
    27982799      begin
    2799         NewOwner := BorderChanges[i div 8] shr (i mod 8 * 4) and $F;
     2800        NewOwner := BorderChanges[I div 8] shr (I mod 8 * 4) and $F;
    28002801        Loc := dLoc(OriginLoc, dx, dy);
    28012802        if (Loc >= 0) and (Cardinal(NewOwner) <> RealMap[Loc] shr 27) then
    28022803          ChangeTerritory(Loc, NewOwner);
    2803         inc(i);
    2804       end;
    2805   end;
    2806 end;
    2807 
    2808 procedure CheckBorders(OriginLoc, PlayerLosingCity: integer);
     2804        Inc(I);
     2805      end;
     2806  end;
     2807end;
     2808
     2809procedure CheckBorders(OriginLoc, PlayerLosingCity: Integer);
    28092810// OriginLoc: only changes in CountryRadius around this location possible,
    28102811// -1 for complete map, -2 for double-check (no more changes allowed)
     
    28122813// player's territory, -1 for full border recalculation
    28132814var
    2814   i, r, Loc, Loc1, dx, dy, p1, p2, cix, NewDist, dxMax, dyMax, OldOwner, V8: Integer;
     2815  I, R, Loc, Loc1, dx, dy, p1, p2, cix, NewDist, dxMax, dyMax, OldOwner, V8: Integer;
    28152816  NewOwner: Cardinal;
    28162817  Adjacent: TVicinity8Loc;
    2817   AtPeace: array [0 .. nPl, 0 .. nPl] of boolean;
     2818  AtPeace: array [0 .. nPl, 0 .. nPl] of Boolean;
    28182819  Country, FormerCountry, { to who's country a tile belongs }
    28192820  Dist, FormerDist, StolenDist: array [0 .. lxmax * lymax - 1] of ShortInt;
     
    28272828        StolenDist[RW[PlayerLosingCity].City[cix].Loc] := 0;
    28282829
    2829     for r := 1 to CountryRadius shr 1 do
    2830     begin
    2831       move(StolenDist, FormerDist, MapSize);
     2830    for R := 1 to CountryRadius shr 1 do
     2831    begin
     2832      Move(StolenDist, FormerDist, MapSize);
    28322833      for Loc := 0 to MapSize - 1 do
    28332834        if (FormerDist[Loc] <= CountryRadius - 2)
     
    28612862        end;
    28622863
    2863   for r := 1 to CountryRadius shr 1 do
    2864   begin
    2865     move(Country, FormerCountry, MapSize);
    2866     move(Dist, FormerDist, MapSize);
     2864  for R := 1 to CountryRadius shr 1 do
     2865  begin
     2866    Move(Country, FormerCountry, MapSize);
     2867    Move(Dist, FormerDist, MapSize);
    28672868    for Loc := 0 to MapSize - 1 do
    28682869      if (FormerDist[Loc] <= CountryRadius - 2) // use same conditions as above!
     
    28702871        (1 shl fShore + 1 shl fMountains + 1 shl fArctic) = 0) then
    28712872      begin
    2872         assert(FormerCountry[Loc] >= 0);
     2873        Assert(FormerCountry[Loc] >= 0);
    28732874        V8_to_Loc(Loc, Adjacent);
    28742875        for V8 := 0 to 7 do
     
    28852886  end;
    28862887
    2887   FillChar(AtPeace, SizeOf(AtPeace), false);
     2888  FillChar(AtPeace, SizeOf(AtPeace), False);
    28882889  for p1 := 0 to nPl - 1 do
    28892890    if 1 shl p1 and GAlive <> 0 then
     
    28912892        if (p2 <> p1) and (1 shl p2 and GAlive <> 0) and
    28922893          (RW[p1].Treaty[p2] >= trPeace) then
    2893           AtPeace[p1, p2] := true;
     2894          AtPeace[p1, p2] := True;
    28942895
    28952896  if OriginLoc >= 0 then
    28962897  begin // update area only
    2897     i := 0;
     2898    I := 0;
    28982899    FillChar(BorderChanges, SizeOf(BorderChanges), 0);
    28992900    dyMax := 0;
    29002901    while (dyMax + 1) + (dyMax + 1) shr 1 <= CountryRadius do
    2901       inc(dyMax);
     2902      Inc(dyMax);
    29022903    for dy := -dyMax to dyMax do
    29032904    begin
     
    29052906      while abs(dy) + (dxMax + 2) + abs(abs(dy) - (dxMax + 2)) shr 1 <=
    29062907        CountryRadius do
    2907         inc(dxMax, 2);
     2908        Inc(dxMax, 2);
    29082909      for dx := -dxMax to dxMax do
    29092910        if (dy + dx) and 1 = 0 then
     
    29212922              else
    29222923                ChangeTerritory(Loc, NewOwner);
    2923             BorderChanges[i shr 3] := BorderChanges[i shr 3] or
    2924               ((NewOwner shl ((i and 7) * 4)) and $ffffffff);
     2924            BorderChanges[I shr 3] := BorderChanges[I shr 3] or
     2925              ((NewOwner shl ((I and 7) * 4)) and $ffffffff);
    29252926          end;
    2926           inc(i);
     2927          Inc(I);
    29272928        end;
    29282929    end;
     
    29372938      then
    29382939      begin
    2939         assert(OriginLoc <> -2); // test if border saving works
     2940        Assert(OriginLoc <> -2); // test if border saving works
    29402941        ChangeTerritory(Loc, NewOwner);
    29412942      end;
     
    29442945{$IFOPT O-} if OriginLoc <> -2 then
    29452946    CheckBorders(-2); {$ENDIF} // check: single pass should do!
    2946 end; // CheckBorders
    2947 
    2948 procedure LogCheckBorders(p, cix, PlayerLosingCity: integer);
    2949 begin
    2950   CheckBorders(RW[p].City[cix].Loc, PlayerLosingCity);
    2951   IntServer(sIntExpandTerritory, p, cix, BorderChanges);
     2947end;
     2948
     2949procedure LogCheckBorders(P, cix, PlayerLosingCity: Integer);
     2950begin
     2951  CheckBorders(RW[P].City[cix].Loc, PlayerLosingCity);
     2952  IntServer(sIntExpandTerritory, P, cix, BorderChanges);
    29522953end;
    29532954
     
    29572958}
    29582959
    2959 procedure CreateUnit(p, mix: integer);
    2960 begin
    2961   with RW[p] do
     2960procedure CreateUnit(P, mix: Integer);
     2961begin
     2962  with RW[P] do
    29622963  begin
    29632964    Un[nUn].mix := mix;
    29642965    with Un[nUn] do
    29652966    begin
    2966       ID := UnBuilt[p];
    2967       inc(UnBuilt[p]);
     2967      ID := UnBuilt[P];
     2968      Inc(UnBuilt[P]);
    29682969      Status := 0;
    29692970      SavedStatus := 0;
    2970       inc(Model[mix].Built);
     2971      Inc(Model[mix].Built);
    29712972      Home := -1;
    29722973      Health := 100;
     
    29762977      begin
    29772978        Fuel := Model[mix].Cap[mcFuel];
    2978         Flags := Flags or unBombsLoaded
     2979        Flags := Flags or unBombsLoaded;
    29792980      end;
    29802981      Job := jNone;
     
    29842985      Master := -1;
    29852986    end;
    2986     inc(nUn);
     2987    Inc(nUn);
    29872988  end
    29882989end;
    29892990
    2990 procedure FreeUnit(p, uix: integer);
     2991procedure FreeUnit(P, uix: Integer);
    29912992// loc or master should be set after call
    29922993// implementation is critical for loading performance, change carefully
    29932994var
    2994   Loc0, uix1: integer;
    2995   Occ, ZoC: boolean;
    2996 begin
    2997   with RW[p].Un[uix] do
     2995  Loc0, uix1: Integer;
     2996  Occ, ZoC: Boolean;
     2997begin
     2998  with RW[P].Un[uix] do
    29982999  begin
    29993000    Job := jNone;
    30003001    Flags := Flags and not(unFortified or unMountainDelay);
    3001     Loc0 := Loc
     3002    Loc0 := Loc;
    30023003  end;
    30033004  if Occupant[Loc0] >= 0 then
    30043005  begin
    3005     assert(Occupant[Loc0] = p);
    3006     Occ := false;
    3007     ZoC := false;
    3008     for uix1 := 0 to RW[p].nUn - 1 do
    3009       with RW[p].Un[uix1] do
     3006    Assert(Occupant[Loc0] = P);
     3007    Occ := False;
     3008    ZoC := False;
     3009    for uix1 := 0 to RW[P].nUn - 1 do
     3010      with RW[P].Un[uix1] do
    30103011        if (Loc = Loc0) and (Master < 0) and (uix1 <> uix) then
    30113012        begin
    3012           Occ := true;
    3013           if RW[p].Model[mix].Flags and mdZOC <> 0 then
     3013          Occ := True;
     3014          if RW[P].Model[mix].Flags and mdZOC <> 0 then
    30143015          begin
    3015             ZoC := true;
    3016             Break
    3017           end
     3016            ZoC := True;
     3017            Break;
     3018          end;
    30183019        end;
    30193020    if not Occ then
     
    30243025end;
    30253026
    3026 procedure PlaceUnit(p, uix: integer);
    3027 begin
    3028   with RW[p].Un[uix] do
    3029   begin
    3030     Occupant[Loc] := p;
    3031     if RW[p].Model[mix].Flags and mdZOC <> 0 then
     3027procedure PlaceUnit(P, uix: Integer);
     3028begin
     3029  with RW[P].Un[uix] do
     3030  begin
     3031    Occupant[Loc] := P;
     3032    if RW[P].Model[mix].Flags and mdZOC <> 0 then
    30323033      ZoCMap[Loc] := 1;
    30333034  end;
    30343035end;
    30353036
    3036 procedure CountLost(p, mix, Enemy: integer);
    3037 begin
    3038   Inc(RW[p].Model[mix].Lost);
    3039   TellAboutModel(Enemy, p, mix);
    3040   Inc(Destroyed[Enemy, p, mix]);
    3041 end;
    3042 
    3043 procedure RemoveUnit(p, uix: integer; Enemy: integer = -1);
     3037procedure CountLost(P, mix, Enemy: Integer);
     3038begin
     3039  Inc(RW[P].Model[mix].Lost);
     3040  TellAboutModel(Enemy, P, mix);
     3041  Inc(Destroyed[Enemy, P, mix]);
     3042end;
     3043
     3044procedure RemoveUnit(P, uix: Integer; Enemy: Integer = -1);
    30443045// use enemy only from inside sMoveUnit if attack
    30453046var
    3046   uix1: integer;
    3047 begin
    3048   with RW[p].Un[uix] do
    3049   begin
    3050     assert((Loc >= 0) or (RW[p].Model[mix].Kind = mkDiplomat));
     3047  uix1: Integer;
     3048begin
     3049  with RW[P].Un[uix] do
     3050  begin
     3051    Assert((Loc >= 0) or (RW[P].Model[mix].Kind = mkDiplomat));
    30513052    // already freed when spy mission
    30523053    if Loc >= 0 then
    3053       FreeUnit(p, uix);
     3054      FreeUnit(P, uix);
    30543055    if Master >= 0 then
    3055       if RW[p].Model[mix].Domain = dAir then
    3056         dec(RW[p].Un[Master].AirLoad)
     3056      if RW[P].Model[mix].Domain = dAir then
     3057        Dec(RW[P].Un[Master].AirLoad)
    30573058      else
    3058         dec(RW[p].Un[Master].TroopLoad);
     3059        Dec(RW[P].Un[Master].TroopLoad);
    30593060    if (TroopLoad > 0) or (AirLoad > 0) then
    3060       for uix1 := 0 to RW[p].nUn - 1 do
    3061         if (RW[p].Un[uix1].Loc >= 0) and (RW[p].Un[uix1].Master = uix) then
     3061      for uix1 := 0 to RW[P].nUn - 1 do
     3062        if (RW[P].Un[uix1].Loc >= 0) and (RW[P].Un[uix1].Master = uix) then
    30623063        { unit mastered by removed unit -- remove too }
    30633064        begin
    3064           RW[p].Un[uix1].Loc := -1;
     3065          RW[P].Un[uix1].Loc := -1;
    30653066          if Enemy >= 0 then
    3066             CountLost(p, RW[p].Un[uix1].mix, Enemy);
     3067            CountLost(P, RW[P].Un[uix1].mix, Enemy);
    30673068        end;
    30683069    Loc := -1;
    30693070    if Enemy >= 0 then
    3070       CountLost(p, mix, Enemy);
    3071   end;
    3072 end;
    3073 
    3074 procedure RemoveUnit_UpdateMap(p, uix: integer);
     3071      CountLost(P, mix, Enemy);
     3072  end;
     3073end;
     3074
     3075procedure RemoveUnit_UpdateMap(P, uix: Integer);
    30753076var
    30763077  Loc0: Integer;
    30773078begin
    3078   Loc0 := RW[p].Un[uix].Loc;
    3079   RemoveUnit(p, uix);
     3079  Loc0 := RW[P].Un[uix].Loc;
     3080  RemoveUnit(P, uix);
    30803081  if Mode > moLoading_Fast then
    30813082    UpdateUnitMap(Loc0);
    30823083end;
    30833084
    3084 procedure RemoveAllUnits(p, Loc: integer; Enemy: integer = -1);
    3085 var
    3086   uix: integer;
    3087 begin
    3088   for uix := 0 to RW[p].nUn - 1 do
    3089     if RW[p].Un[uix].Loc = Loc then
     3085procedure RemoveAllUnits(P, Loc: Integer; Enemy: Integer = -1);
     3086var
     3087  uix: Integer;
     3088begin
     3089  for uix := 0 to RW[P].nUn - 1 do
     3090    if RW[P].Un[uix].Loc = Loc then
    30903091    begin
    30913092      if Enemy >= 0 then
    3092         CountLost(p, RW[p].Un[uix].mix, Enemy);
    3093       RW[p].Un[uix].Loc := -1
     3093        CountLost(P, RW[P].Un[uix].mix, Enemy);
     3094      RW[P].Un[uix].Loc := -1;
    30943095    end;
    30953096  Occupant[Loc] := -1;
     
    30973098end;
    30983099
    3099 procedure RemoveDomainUnits(d, p, Loc: integer);
    3100 var
    3101   uix: integer;
    3102 begin
    3103   for uix := 0 to RW[p].nUn - 1 do
    3104     if (RW[p].Model[RW[p].Un[uix].mix].Domain = d) and (RW[p].Un[uix].Loc = Loc)
     3100procedure RemoveDomainUnits(D, P, Loc: Integer);
     3101var
     3102  uix: Integer;
     3103begin
     3104  for uix := 0 to RW[P].nUn - 1 do
     3105    if (RW[P].Model[RW[P].Un[uix].mix].Domain = D) and (RW[P].Un[uix].Loc = Loc)
    31053106    then
    3106       RemoveUnit(p, uix);
    3107 end;
    3108 
    3109 procedure FoundCity(p, FoundLoc: integer);
    3110 var
    3111   p1, cix1, V21, dx, dy: integer;
    3112 begin
    3113   if RW[p].nCity = ncmax then
    3114     exit;
    3115   inc(RW[p].nCity);
    3116   with RW[p].City[RW[p].nCity - 1] do
     3107      RemoveUnit(P, uix);
     3108end;
     3109
     3110procedure FoundCity(P, FoundLoc: Integer);
     3111var
     3112  p1, cix1, V21, dx, dy: Integer;
     3113begin
     3114  if RW[P].nCity = ncmax then
     3115    Exit;
     3116  Inc(RW[P].nCity);
     3117  with RW[P].City[RW[P].nCity - 1] do
    31173118  begin
    31183119    Size := 2;
     
    31303131    if UsedByCity[FoundLoc] >= 0 then
    31313132    begin { central tile is exploited - toggle in exploiting city }
    3132       p1 := p;
     3133      p1 := P;
    31333134      SearchCity(UsedByCity[FoundLoc], p1, cix1);
    31343135      dxdy(UsedByCity[FoundLoc], FoundLoc, dx, dy);
     
    31413142      (fTerrain or fSpecial or fRiver or nPl shl 27) or fCity;
    31423143
    3143     ChangeTerritory(Loc, p)
    3144   end;
    3145 end;
    3146 
    3147 procedure StealCity(p, cix: integer; SaveUnits: boolean);
    3148 var
    3149   i, j, uix1, cix1, nearest: integer;
    3150 begin
    3151   for i := 0 to nWonder - 1 do
    3152     if RW[p].City[cix].Built[i] = 1 then
    3153     begin
    3154       GWonder[i].EffectiveOwner := -1;
    3155       if i = woPyramids then
     3144    ChangeTerritory(Loc, P);
     3145  end;
     3146end;
     3147
     3148procedure StealCity(P, cix: Integer; SaveUnits: Boolean);
     3149var
     3150  I, J, uix1, cix1, nearest: Integer;
     3151begin
     3152  for I := 0 to nWonder - 1 do
     3153    if RW[P].City[cix].Built[I] = 1 then
     3154    begin
     3155      GWonder[I].EffectiveOwner := -1;
     3156      if I = woPyramids then
    31563157        FreeSlaves;
    3157       if i = woEiffel then // deactivate expired wonders
    3158         for j := 0 to nWonder - 1 do
    3159           if GWonder[j].EffectiveOwner = p then
    3160             CheckExpiration(j);
    3161     end;
    3162   for i := nWonder to nImp - 1 do
    3163     if (Imp[i].Kind <> ikCommon) and (RW[p].City[cix].Built[i] > 0) then
     3158      if I = woEiffel then // deactivate expired wonders
     3159        for J := 0 to nWonder - 1 do
     3160          if GWonder[J].EffectiveOwner = P then
     3161            CheckExpiration(J);
     3162    end;
     3163  for I := nWonder to nImp - 1 do
     3164    if (Imp[I].Kind <> ikCommon) and (RW[P].City[cix].Built[I] > 0) then
    31643165    begin { destroy national projects }
    3165       RW[p].NatBuilt[i] := 0;
    3166       if i = imGrWall then
    3167         GrWallContinent[p] := -1;
    3168     end;
    3169 
    3170   for uix1 := 0 to RW[p].nUn - 1 do
    3171     with RW[p].Un[uix1] do
     3166      RW[P].NatBuilt[I] := 0;
     3167      if I = imGrWall then
     3168        GrWallContinent[P] := -1;
     3169    end;
     3170
     3171  for uix1 := 0 to RW[P].nUn - 1 do
     3172    with RW[P].Un[uix1] do
    31723173      if (Loc >= 0) and (Home = cix) then
    31733174        if SaveUnits then
    31743175        begin // support units by nearest other city
    31753176          nearest := -1;
    3176           for cix1 := 0 to RW[p].nCity - 1 do
    3177             if (cix1 <> cix) and (RW[p].City[cix1].Loc >= 0) and
    3178               ((nearest < 0) or (Distance(RW[p].City[cix1].Loc, Loc) <
    3179               Distance(RW[p].City[nearest].Loc, Loc))) then
     3177          for cix1 := 0 to RW[P].nCity - 1 do
     3178            if (cix1 <> cix) and (RW[P].City[cix1].Loc >= 0) and
     3179              ((nearest < 0) or (Distance(RW[P].City[cix1].Loc, Loc) <
     3180              Distance(RW[P].City[nearest].Loc, Loc))) then
    31803181              nearest := cix1;
    3181           Home := nearest
     3182          Home := nearest;
    31823183        end
    31833184        else
    3184           RemoveUnit(p, uix1); // destroy supported units
    3185 end;
    3186 
    3187 procedure DestroyCity(p, cix: integer; SaveUnits: boolean);
    3188 var
    3189   i, V21: integer;
     3185          RemoveUnit(P, uix1); // destroy supported units
     3186end;
     3187
     3188procedure DestroyCity(P, cix: Integer; SaveUnits: Boolean);
     3189var
     3190  I, V21: Integer;
    31903191  Radius: TVicinity21Loc;
    31913192begin
    3192   StealCity(p, cix, SaveUnits);
    3193   with RW[p].City[cix] do begin
    3194     for i := 0 to nWonder - 1 do
    3195       if Built[i] > 0 then
    3196         GWonder[i].CityID := WonderDestroyed;
     3193  StealCity(P, cix, SaveUnits);
     3194  with RW[P].City[cix] do begin
     3195    for I := 0 to nWonder - 1 do
     3196      if Built[I] > 0 then
     3197        GWonder[I].CityID := WonderDestroyed;
    31973198    V21_to_Loc(Loc, Radius);
    31983199    for V21 := 1 to 26 do
     
    32003201        UsedByCity[Radius[V21]] := -1;
    32013202    RealMap[Loc] := RealMap[Loc] and not fCity;
    3202     Loc := -1
    3203   end;
    3204 end;
    3205 
    3206 procedure ChangeCityOwner(pOld, cixOld, pNew: integer);
    3207 var
    3208   i, j, cix1, Loc1, V21: integer;
     3203    Loc := -1;
     3204  end;
     3205end;
     3206
     3207procedure ChangeCityOwner(pOld, cixOld, pNew: Integer);
     3208var
     3209  I, J, cix1, Loc1, V21: Integer;
    32093210  Radius: TVicinity21Loc;
    32103211begin
    3211   inc(RW[pNew].nCity);
     3212  Inc(RW[pNew].nCity);
    32123213  RW[pNew].City[RW[pNew].nCity - 1] := RW[pOld].City[cixOld];
    3213   StealCity(pOld, cixOld, false);
     3214  StealCity(pOld, cixOld, False);
    32143215  RW[pOld].City[cixOld].Loc := -1;
    32153216  with RW[pNew].City[(RW[pNew].nCity - 1)] do
     
    32303231      begin
    32313232        Loc1 := Radius[V21];
    3232         assert((Loc1 >= 0) and (Loc1 < MapSize) and (UsedByCity[Loc1] = Loc));
     3233        Assert((Loc1 >= 0) and (Loc1 < MapSize) and (UsedByCity[Loc1] = Loc));
    32333234        if (ZoCMap[Loc1] > 0) and (Occupant[Loc1] <> pNew) and
    32343235          (RW[pNew].Treaty[Occupant[Loc1]] < trAlliance) then
     
    32423243    Built[imTownHall] := 0;
    32433244    Built[imCourt] := 0;
    3244     for i := nWonder to nImp - 1 do
    3245       if Imp[i].Kind <> ikCommon then
    3246         Built[i] := 0; { destroy national projects }
    3247     for i := 0 to nWonder - 1 do
    3248       if Built[i] = 1 then
     3245    for I := nWonder to nImp - 1 do
     3246      if Imp[I].Kind <> ikCommon then
     3247        Built[I] := 0; { destroy national projects }
     3248    for I := 0 to nWonder - 1 do
     3249      if Built[I] = 1 then
    32493250      begin // new wonder owner!
    3250         GWonder[i].EffectiveOwner := pNew;
    3251         if i = woEiffel then // reactivate expired wonders
    3252         begin
    3253           for j := 0 to nWonder - 1 do
    3254             if Imp[j].Expiration >= 0 then
     3251        GWonder[I].EffectiveOwner := pNew;
     3252        if I = woEiffel then // reactivate expired wonders
     3253        begin
     3254          for J := 0 to nWonder - 1 do
     3255            if Imp[J].Expiration >= 0 then
    32553256              for cix1 := 0 to (RW[pNew].nCity - 1) do
    3256                 if RW[pNew].City[cix1].Built[j] = 1 then
    3257                   GWonder[j].EffectiveOwner := pNew;
     3257                if RW[pNew].City[cix1].Built[J] = 1 then
     3258                  GWonder[J].EffectiveOwner := pNew;
    32583259        end
    32593260        else
    3260           CheckExpiration(i);
    3261         case i of
     3261          CheckExpiration(I);
     3262        case I of
    32623263          woLighthouse:
    32633264            CheckSpecialModels(pNew, preLighthouse);
     
    32733274    cix1 := RW[pNew].nEnemyCity - 1;
    32743275    while (cix1 >= 0) and (RW[pNew].EnemyCity[cix1].Loc <> Loc) do
    3275       dec(cix1);
    3276     assert(cix1 >= 0);
     3276      Dec(cix1);
     3277    Assert(cix1 >= 0);
    32773278    RW[pNew].EnemyCity[cix1].Loc := -1;
    32783279
     
    32813282end;
    32823283
    3283 procedure CompleteJob(p, Loc, Job: integer);
    3284 var
    3285   ChangedTerrain, p1: integer;
    3286 begin
    3287   assert(Job <> jCity);
     3284procedure CompleteJob(P, Loc, Job: Integer);
     3285var
     3286  ChangedTerrain, p1: Integer;
     3287begin
     3288  Assert(Job <> jCity);
    32883289  ChangedTerrain := -1;
    32893290  case Job of
     
    33273328        if not(RealMap[Loc] and fTerrain in TerrType_Canalable) then
    33283329        begin
    3329           RemoveDomainUnits(dSea, p, Loc);
     3330          RemoveDomainUnits(dSea, P, Loc);
    33303331          RealMap[Loc] := RealMap[Loc] and not fCanal;
    33313332        end;
     
    33393340      begin
    33403341        if RealMap[Loc] and fTerImp = tiBase then
    3341           RemoveDomainUnits(dAir, p, Loc);
     3342          RemoveDomainUnits(dAir, P, Loc);
    33423343        RealMap[Loc] := RealMap[Loc] and not fTerImp
    33433344      end
    33443345      else if RealMap[Loc] and fCanal <> 0 then
    33453346      begin
    3346         RemoveDomainUnits(dSea, p, Loc);
     3347        RemoveDomainUnits(dSea, P, Loc);
    33473348        RealMap[Loc] := RealMap[Loc] and not fCanal
    33483349      end
     
    33743375          fPoll) or RealMap[Loc] and (fTerrain or fSpecial or fTerImp or
    33753376          fRoad or fRR or fCanal or fPoll);
    3376 end; // CompleteJob
     3377end;
    33773378
    33783379{
     
    33803381  ____________________________________________________________________
    33813382}
    3382 procedure GiveCivilReport(p, pAbout: integer);
    3383 begin
    3384   with RW[p].EnemyReport[pAbout]^ do
     3383procedure GiveCivilReport(P, pAbout: Integer);
     3384begin
     3385  with RW[P].EnemyReport[pAbout]^ do
    33853386  begin
    33863387    // general info
    33873388    TurnOfCivilReport := LastValidStat[pAbout];
    3388     move(RW[pAbout].Treaty, Treaty, SizeOf(Treaty));
     3389    Move(RW[pAbout].Treaty, Treaty, SizeOf(Treaty));
    33893390    Government := RW[pAbout].Government;
    33903391    Money := RW[pAbout].Money;
     
    33953396    if ResearchDone > 100 then
    33963397      ResearchDone := 100;
    3397     move(RW[pAbout].Tech, Tech, nAdv);
    3398   end;
    3399 end;
    3400 
    3401 procedure GiveMilReport(p, pAbout: integer);
    3402 var
    3403   uix, mix: integer;
    3404 begin
    3405   with RW[p].EnemyReport[pAbout]^ do
     3398    Move(RW[pAbout].Tech, Tech, nAdv);
     3399  end;
     3400end;
     3401
     3402procedure GiveMilReport(P, pAbout: Integer);
     3403var
     3404  uix, mix: Integer;
     3405begin
     3406  with RW[P].EnemyReport[pAbout]^ do
    34063407  begin
    34073408    TurnOfMilReport := LastValidStat[pAbout];
     
    34093410    for mix := 0 to RW[pAbout].nModel - 1 do
    34103411    begin
    3411       TellAboutModel(p, pAbout, mix);
     3412      TellAboutModel(P, pAbout, mix);
    34123413      UnCount[mix] := 0
    34133414    end;
    34143415    for uix := 0 to RW[pAbout].nUn - 1 do
    34153416      if RW[pAbout].Un[uix].Loc >= 0 then
    3416         inc(UnCount[RW[pAbout].Un[uix].mix]);
    3417   end;
    3418 end;
    3419 
    3420 procedure ShowPrice(pSender, pTarget, Price: integer);
     3417        Inc(UnCount[RW[pAbout].Un[uix].mix]);
     3418  end;
     3419end;
     3420
     3421procedure ShowPrice(pSender, pTarget, Price: Integer);
    34213422begin
    34223423  case Price and opMask of
     
    34333434end;
    34343435
    3435 function CopyCivilReport(pSender, pTarget, pAbout: integer): boolean;
    3436 var
    3437   i: integer;
     3436function CopyCivilReport(pSender, pTarget, pAbout: Integer): Boolean;
     3437var
     3438  I: Integer;
    34383439  rSender, rTarget: ^TEnemyReport;
    34393440begin // copy third nation civil report
    3440   result := false;
     3441  Result := False;
    34413442  if RW[pTarget].Treaty[pAbout] = trNoContact then
    34423443    IntroduceEnemy(pTarget, pAbout);
    3443   rSender := pointer(RW[pSender].EnemyReport[pAbout]);
    3444   rTarget := pointer(RW[pTarget].EnemyReport[pAbout]);
     3444  rSender := Pointer(RW[pSender].EnemyReport[pAbout]);
     3445  rTarget := Pointer(RW[pTarget].EnemyReport[pAbout]);
    34453446  if rSender.TurnOfCivilReport > rTarget.TurnOfCivilReport then
    34463447  begin // only if newer than current information
     
    34513452    rTarget.ResearchTech := rSender.ResearchTech;
    34523453    rTarget.ResearchDone := rSender.ResearchDone;
    3453     result := true;
    3454   end;
    3455   for i := 0 to nAdv - 1 do
    3456     if rTarget.Tech[i] < rSender.Tech[i] then
    3457     begin
    3458       rTarget.Tech[i] := rSender.Tech[i];
    3459       result := true;
    3460     end;
    3461 end;
    3462 
    3463 function CopyMilReport(pSender, pTarget, pAbout: integer): boolean;
    3464 var
    3465   mix: integer;
     3454    Result := True;
     3455  end;
     3456  for I := 0 to nAdv - 1 do
     3457    if rTarget.Tech[I] < rSender.Tech[I] then
     3458    begin
     3459      rTarget.Tech[I] := rSender.Tech[I];
     3460      Result := True;
     3461    end;
     3462end;
     3463
     3464function CopyMilReport(pSender, pTarget, pAbout: Integer): Boolean;
     3465var
     3466  mix: Integer;
    34663467  rSender, rTarget: ^TEnemyReport;
    34673468begin // copy third nation military report
    3468   result := false;
     3469  Result := False;
    34693470  if RW[pTarget].Treaty[pAbout] = trNoContact then
    34703471    IntroduceEnemy(pTarget, pAbout);
    3471   rSender := pointer(RW[pSender].EnemyReport[pAbout]);
    3472   rTarget := pointer(RW[pTarget].EnemyReport[pAbout]);
     3472  rSender := Pointer(RW[pSender].EnemyReport[pAbout]);
     3473  rTarget := Pointer(RW[pTarget].EnemyReport[pAbout]);
    34733474  if rSender.TurnOfMilReport > rTarget.TurnOfMilReport then
    34743475  begin // only if newer than current information
    34753476    rTarget.TurnOfMilReport := rSender.TurnOfMilReport;
    34763477    rTarget.nModelCounted := rSender.nModelCounted;
    3477     move(rSender.UnCount, rTarget.UnCount, 2 * rSender.nModelCounted);
     3478    Move(rSender.UnCount, rTarget.UnCount, 2 * rSender.nModelCounted);
    34783479    for mix := 0 to rTarget.nModelCounted - 1 do
    34793480      TellAboutModel(pTarget, pAbout, mix);
    3480     result := true;
    3481   end;
    3482 end;
    3483 
    3484 procedure CopyModel(pSender, pTarget, mix: integer);
    3485 var
    3486   i: integer;
     3481    Result := True;
     3482  end;
     3483end;
     3484
     3485procedure CopyModel(pSender, pTarget, mix: Integer);
     3486var
     3487  I: Integer;
    34873488  miSender, miTarget: TModelInfo;
    3488   ok: boolean;
     3489  ok: Boolean;
    34893490begin
    34903491  // only if target doesn't already have a model like this
    34913492  ok := RW[pTarget].nModel < nmmax;
    34923493  MakeModelInfo(pSender, mix, RW[pSender].Model[mix], miSender);
    3493   for i := 0 to RW[pTarget].nModel - 1 do
    3494   begin
    3495     MakeModelInfo(pTarget, i, RW[pTarget].Model[i], miTarget);
     3494  for I := 0 to RW[pTarget].nModel - 1 do
     3495  begin
     3496    MakeModelInfo(pTarget, I, RW[pTarget].Model[I], miTarget);
    34963497    if IsSameModel(miSender, miTarget) then
    3497       ok := false;
     3498      ok := False;
    34983499  end;
    34993500  if ok then
     
    35103511      Lost := 0;
    35113512    end;
    3512     inc(RW[pTarget].nModel);
    3513     inc(Researched[pTarget]);
     3513    Inc(RW[pTarget].nModel);
     3514    Inc(Researched[pTarget]);
    35143515    TellAboutModel(pSender, pTarget, RW[pTarget].nModel - 1);
    35153516  end;
    35163517end;
    35173518
    3518 procedure CopyMap(pSender, pTarget: integer);
    3519 var
    3520   Loc, i, cix: integer;
     3519procedure CopyMap(pSender, pTarget: Integer);
     3520var
     3521  Loc, I, cix: Integer;
    35213522  Tile: Cardinal;
    35223523begin
     
    35283529      if Tile and fCity <> 0 then
    35293530      begin
    3530         i := 0;
    3531         while (i < RW[pTarget].nEnemyCity) and
    3532           (RW[pTarget].EnemyCity[i].Loc <> Loc) do
    3533           inc(i);
    3534         if i = RW[pTarget].nEnemyCity then
    3535         begin
    3536           inc(RW[pTarget].nEnemyCity);
    3537           assert(RW[pTarget].nEnemyCity < necmax);
    3538           RW[pTarget].EnemyCity[i].Status := 0;
    3539           RW[pTarget].EnemyCity[i].SavedStatus := 0;
     3531        I := 0;
     3532        while (I < RW[pTarget].nEnemyCity) and
     3533          (RW[pTarget].EnemyCity[I].Loc <> Loc) do
     3534          Inc(I);
     3535        if I = RW[pTarget].nEnemyCity then
     3536        begin
     3537          Inc(RW[pTarget].nEnemyCity);
     3538          Assert(RW[pTarget].nEnemyCity < necmax);
     3539          RW[pTarget].EnemyCity[I].Status := 0;
     3540          RW[pTarget].EnemyCity[I].SavedStatus := 0;
    35403541        end;
    35413542        if Tile and fOwned <> 0 then
     
    35433544          cix := RW[pSender].nCity - 1;
    35443545          while (cix >= 0) and (RW[pSender].City[cix].Loc <> Loc) do
    3545             dec(cix);
    3546           MakeCityInfo(pSender, cix, RW[pTarget].EnemyCity[i]);
     3546            Dec(cix);
     3547          MakeCityInfo(pSender, cix, RW[pTarget].EnemyCity[I]);
    35473548        end
    35483549        else // city not owned by sender -- copy old info
     
    35503551          cix := RW[pSender].nEnemyCity - 1;
    35513552          while (cix >= 0) and (RW[pSender].EnemyCity[cix].Loc <> Loc) do
    3552             dec(cix);
    3553           RW[pTarget].EnemyCity[i] := RW[pSender].EnemyCity[cix];
     3553            Dec(cix);
     3554          RW[pTarget].EnemyCity[I] := RW[pSender].EnemyCity[cix];
    35543555        end;
    35553556      end
     
    35653566
    35663567      if RW[pTarget].Map[Loc] and fTerrain = fUNKNOWN then
    3567         inc(Discovered[pTarget]);
     3568        Inc(Discovered[pTarget]);
    35683569      RW[pTarget].Map[Loc] := RW[pTarget].Map[Loc] and fInEnemyZoC
    35693570      // always preserve this flag!
     
    35813582end;
    35823583
    3583 function PayPrice(pSender, pTarget, Price: integer; execute: boolean): boolean;
    3584 var
    3585   pSubject, i, n, NewTreaty: integer;
    3586 begin
    3587   result := true;
     3584function PayPrice(pSender, pTarget, Price: Integer; execute: Boolean): Boolean;
     3585var
     3586  pSubject, I, N, NewTreaty: Integer;
     3587begin
     3588  Result := True;
    35883589  case Price and opMask of
    35893590    opCivilReport: // + turn + concerned player shl 16
     
    35913592        pSubject := Price shr 16 and $F;
    35923593        if pTarget = pSubject then
    3593           result := false
     3594          Result := False
    35943595        else if pSender = pSubject then
    35953596        begin
    35963597          if execute then
    3597             GiveCivilReport(pTarget, pSender)
     3598            GiveCivilReport(pTarget, pSender);
    35983599        end
    35993600        else if RW[pSender].EnemyReport[pSubject].TurnOfCivilReport < 0 then
    3600           result := false
     3601          Result := False
    36013602        else if execute then
    36023603          CopyCivilReport(pSender, pTarget, pSubject);
     
    36063607        pSubject := Price shr 16 and $F;
    36073608        if pTarget = pSubject then
    3608           result := false
     3609          Result := False
    36093610        else if pSender = pSubject then
    36103611        begin
    36113612          if execute then
    3612             GiveMilReport(pTarget, pSender)
     3613            GiveMilReport(pTarget, pSender);
    36133614        end
    36143615        else if RW[pSender].EnemyReport[pSubject].TurnOfMilReport < 0 then
    3615           result := false
     3616          Result := False
    36163617        else if execute then
    3617           CopyMilReport(pSender, pTarget, pSubject)
     3618          CopyMilReport(pSender, pTarget, pSubject);
    36183619      end;
    36193620    opMap:
     
    36283629        begin // agreed treaty end
    36293630          if execute then
    3630             CancelTreaty(pSender, pTarget, false)
     3631            CancelTreaty(pSender, pTarget, False);
    36313632        end
    36323633        else
     
    36393640            NewTreaty := trPeace;
    36403641          if NewTreaty < 0 then
    3641             result := false
     3642            Result := False
    36423643          else if execute then
    36433644          begin
    3644             assert(NewTreaty > RW[pSender].Treaty[pTarget]);
     3645            Assert(NewTreaty > RW[pSender].Treaty[pTarget]);
    36453646            RW[pSender].Treaty[pTarget] := NewTreaty;
    36463647            RW[pTarget].Treaty[pSender] := NewTreaty;
     
    36713672    opShipParts: // + number + part type shl 16
    36723673      begin
    3673         n := Price and $FFFF; // number
    3674         i := Price shr 16 and $F; // type
    3675         if (i < nShipPart) and (GShip[pSender].Parts[i] >= n) then
     3674        N := Price and $FFFF; // number
     3675        I := Price shr 16 and $F; // type
     3676        if (I < nShipPart) and (GShip[pSender].Parts[I] >= N) then
    36763677        begin
    36773678          if execute then
    36783679          begin
    3679             dec(GShip[pSender].Parts[i], n);
    3680             RW[pSender].Ship[pSender].Parts[i] := GShip[pSender].Parts[i];
    3681             RW[pTarget].Ship[pSender].Parts[i] := GShip[pSender].Parts[i];
     3680            Dec(GShip[pSender].Parts[I], N);
     3681            RW[pSender].Ship[pSender].Parts[I] := GShip[pSender].Parts[I];
     3682            RW[pTarget].Ship[pSender].Parts[I] := GShip[pSender].Parts[I];
    36823683            if RW[pTarget].NatBuilt[imSpacePort] > 0 then
    36833684            begin // space ship control requires space port
    3684               inc(GShip[pTarget].Parts[i], n);
    3685               RW[pSender].Ship[pTarget].Parts[i] := GShip[pTarget].Parts[i];
    3686               RW[pTarget].Ship[pTarget].Parts[i] := GShip[pTarget].Parts[i];
     3685              Inc(GShip[pTarget].Parts[I], N);
     3686              RW[pSender].Ship[pTarget].Parts[I] := GShip[pTarget].Parts[I];
     3687              RW[pTarget].Ship[pTarget].Parts[I] := GShip[pTarget].Parts[I];
    36873688            end;
    36883689          end;
    36893690        end
    36903691        else
    3691           result := false;
     3692          Result := False;
    36923693      end;
    36933694    opMoney: // + value
     
    36973698        if execute then
    36983699        begin
    3699           dec(RW[pSender].Money, Price - opMoney);
    3700           inc(RW[pTarget].Money, Price - opMoney);
     3700          Dec(RW[pSender].Money, Price - opMoney);
     3701          Inc(RW[pTarget].Money, Price - opMoney);
    37013702        end;
    37023703      end
    37033704      else
    3704         result := false;
     3705        Result := False;
    37053706    opTribute: // + value
    37063707      if execute then
     
    37173718      end
    37183719      else
    3719         result := false;
     3720        Result := False;
    37203721    opAllTech:
    37213722      if execute then
    3722         for i := 0 to nAdv - 1 do
    3723           if (RW[pSender].Tech[i] >= tsApplicable) and
    3724             (RW[pTarget].Tech[i] = tsNA) then
     3723        for I := 0 to nAdv - 1 do
     3724          if (RW[pSender].Tech[I] >= tsApplicable) and
     3725            (RW[pTarget].Tech[I] = tsNA) then
    37253726          begin
    3726             SeeTech(pTarget, i);
    3727             RW[pSender].EnemyReport[pTarget].Tech[i] := tsSeen;
    3728             RW[pTarget].EnemyReport[pSender].Tech[i] := tsApplicable;
     3727            SeeTech(pTarget, I);
     3728            RW[pSender].EnemyReport[pTarget].Tech[I] := tsSeen;
     3729            RW[pTarget].EnemyReport[pSender].Tech[I] := tsApplicable;
    37293730          end;
    37303731    opModel: // + model index
     
    37323733      begin
    37333734        if execute then
    3734           CopyModel(pSender, pTarget, Price - opModel)
     3735          CopyModel(pSender, pTarget, Price - opModel);
    37353736      end
    37363737      else
    3737         result := false;
     3738        Result := False;
    37383739    opAllModel:
    37393740      if execute then
    3740         for i := 0 to RW[pSender].nModel - 1 do
    3741         begin
    3742           TellAboutModel(pTarget, pSender, i);
    3743           CopyModel(pSender, pTarget, i);
     3741        for I := 0 to RW[pSender].nModel - 1 do
     3742        begin
     3743          TellAboutModel(pTarget, pSender, I);
     3744          CopyModel(pSender, pTarget, I);
    37443745        end;
    37453746    { opCity: // + city ID
    37463747      begin
    3747       result:=false
     3748      Result:=False
    37483749      end; }
    3749   end
    3750 end;
    3751 
    3752 procedure CancelTreaty(p, pWith: integer; DecreaseCredibility: boolean);
     3750  end;
     3751end;
     3752
     3753procedure CancelTreaty(P, pWith: Integer; DecreaseCredibility: Boolean);
    37533754// side effect: PeaceEnded := bitarray of players with which peace treaty was canceled
    37543755var
    3755   p1, OldTreaty: integer;
    3756 begin
    3757   OldTreaty := RW[p].Treaty[pWith];
     3756  p1, OldTreaty: Integer;
     3757begin
     3758  OldTreaty := RW[P].Treaty[pWith];
    37583759  PeaceEnded := 0;
    37593760  if OldTreaty >= trPeace then
    3760     RW[p].LastCancelTreaty[pWith] := GTurn;
     3761    RW[P].LastCancelTreaty[pWith] := GTurn;
    37613762  if DecreaseCredibility then
    37623763  begin
     
    37643765      trPeace:
    37653766        begin
    3766           RW[p].Credibility := RW[p].Credibility shr 1;
    3767           if RW[p].MaxCredibility > 0 then
    3768             dec(RW[p].MaxCredibility, 10);
    3769           if RW[p].Credibility > RW[p].MaxCredibility then
    3770             RW[p].Credibility := RW[p].MaxCredibility;
     3767          RW[P].Credibility := RW[P].Credibility shr 1;
     3768          if RW[P].MaxCredibility > 0 then
     3769            Dec(RW[P].MaxCredibility, 10);
     3770          if RW[P].Credibility > RW[P].MaxCredibility then
     3771            RW[P].Credibility := RW[P].MaxCredibility;
    37713772        end;
    37723773      trAlliance:
    3773         RW[p].Credibility := RW[p].Credibility * 3 div 4;
    3774     end;
    3775     RW[pWith].EnemyReport[p].Credibility := RW[p].Credibility;
     3774        RW[P].Credibility := RW[P].Credibility * 3 div 4;
     3775    end;
     3776    RW[pWith].EnemyReport[P].Credibility := RW[P].Credibility;
    37763777  end;
    37773778
     
    37793780  begin
    37803781    for p1 := 0 to nPl - 1 do
    3781       if (p1 = pWith) or DecreaseCredibility and (p1 <> p) and
    3782         (RW[pWith].Treaty[p1] = trAlliance) and (RW[p].Treaty[p1] >= trPeace)
     3782      if (p1 = pWith) or DecreaseCredibility and (p1 <> P) and
     3783        (RW[pWith].Treaty[p1] = trAlliance) and (RW[P].Treaty[p1] >= trPeace)
    37833784      then
    37843785      begin
    3785         RW[p].Treaty[p1] := trNone;
    3786         RW[p1].Treaty[p] := trNone;
    3787         RW[p].EvaStart[p1] := -PeaceEvaTurns - 1;
    3788         RW[p1].EvaStart[p] := -PeaceEvaTurns - 1;
    3789         inc(PeaceEnded, 1 shl p1);
     3786        RW[P].Treaty[p1] := trNone;
     3787        RW[p1].Treaty[P] := trNone;
     3788        RW[P].EvaStart[p1] := -PeaceEvaTurns - 1;
     3789        RW[p1].EvaStart[P] := -PeaceEvaTurns - 1;
     3790        Inc(PeaceEnded, 1 shl p1);
    37903791      end;
    37913792    CheckBorders(-1);
    37923793    if (Mode > moLoading_Fast) and (PeaceEnded > 0) then
    3793       RecalcMapZoC(p);
     3794      RecalcMapZoC(P);
    37943795  end
    37953796  else
    37963797  begin
    3797     RW[p].Treaty[pWith] := OldTreaty - 1;
    3798     RW[pWith].Treaty[p] := OldTreaty - 1;
     3798    RW[P].Treaty[pWith] := OldTreaty - 1;
     3799    RW[pWith].Treaty[P] := OldTreaty - 1;
    37993800    if OldTreaty = TrFriendlyContact then
    38003801    begin // necessary for loading
    3801       GiveCivilReport(p, pWith);
    3802       GiveCivilReport(pWith, p);
     3802      GiveCivilReport(P, pWith);
     3803      GiveCivilReport(pWith, P);
    38033804    end
    38043805    else if OldTreaty = trAlliance then
    38053806    begin // necessary for loading
    3806       GiveMilReport(p, pWith);
    3807       GiveMilReport(pWith, p);
     3807      GiveMilReport(P, pWith);
     3808      GiveMilReport(pWith, P);
    38083809    end;
    38093810    if (Mode > moLoading_Fast) and (OldTreaty = trAlliance) then
    38103811    begin
    3811       RecalcMapZoC(p);
     3812      RecalcMapZoC(P);
    38123813      RecalcMapZoC(pWith);
    38133814    end;
     
    38153816  if OldTreaty in [trPeace, trAlliance] then
    38163817  begin
    3817     RecalcPeaceMap(p);
     3818    RecalcPeaceMap(P);
    38183819    RecalcPeaceMap(pWith);
    38193820  end;
    38203821end;
    38213822
    3822 function DoSpyMission(p, pCity, cix, Mission: integer): Cardinal;
    3823 var
    3824   p1: integer;
    3825 begin
    3826   result := 0;
     3823function DoSpyMission(P, pCity, cix, Mission: Integer): Cardinal;
     3824var
     3825  p1: Integer;
     3826begin
     3827  Result := 0;
    38273828  case Mission of
    38283829    smSabotageProd:
     
    38313832    smStealMap:
    38323833      begin
    3833         CopyMap(pCity, p);
    3834         RecalcPeaceMap(p);
     3834        CopyMap(pCity, P);
     3835        RecalcPeaceMap(P);
    38353836      end;
    38363837    smStealCivilReport:
    38373838      begin
    3838         if RW[p].Treaty[pCity] = trNoContact then
    3839           IntroduceEnemy(p, pCity);
    3840         GiveCivilReport(p, pCity);
     3839        if RW[P].Treaty[pCity] = trNoContact then
     3840          IntroduceEnemy(P, pCity);
     3841        GiveCivilReport(P, pCity);
    38413842      end;
    38423843    smStealMilReport:
    38433844      begin
    3844         if RW[p].Treaty[pCity] = trNoContact then
    3845           IntroduceEnemy(p, pCity);
    3846         GiveMilReport(p, pCity);
     3845        if RW[P].Treaty[pCity] = trNoContact then
     3846          IntroduceEnemy(P, pCity);
     3847        GiveMilReport(P, pCity);
    38473848      end;
    38483849    smStealForeignReports:
    38493850      begin
    38503851        for p1 := 0 to nPl - 1 do
    3851           if (p1 <> p) and (p1 <> pCity) and (RW[pCity].EnemyReport[p1] <> nil)
     3852          if (p1 <> P) and (p1 <> pCity) and (RW[pCity].EnemyReport[p1] <> nil)
    38523853          then
    38533854          begin
    38543855            if RW[pCity].EnemyReport[p1].TurnOfCivilReport >= 0 then
    3855               if CopyCivilReport(pCity, p, p1) then
    3856                 result := result or (1 shl (2 * p1));
     3856              if CopyCivilReport(pCity, P, p1) then
     3857                Result := Result or (1 shl (2 * p1));
    38573858            if RW[pCity].EnemyReport[p1].TurnOfMilReport >= 0 then
    3858               if CopyMilReport(pCity, p, p1) then
    3859                 result := result or (2 shl (2 * p1));
     3859              if CopyMilReport(pCity, P, p1) then
     3860                Result := Result or (2 shl (2 * p1));
    38603861          end;
    38613862      end;
     
    38673868  ____________________________________________________________________
    38683869}
    3869 procedure ClearTestFlags(ClearFlags: integer);
    3870 var
    3871   p1: integer;
     3870procedure ClearTestFlags(ClearFlags: Integer);
     3871var
     3872  p1: Integer;
    38723873begin
    38733874  GTestFlags := GTestFlags and (not ClearFlags or tfTested or tfAllTechs or
     
    38783879end;
    38793880
    3880 procedure SetTestFlags(p, SetFlags: integer);
    3881 var
    3882   i, p1, p2, MoreFlags: integer;
     3881procedure SetTestFlags(P, SetFlags: Integer);
     3882var
     3883  I, p1, p2, MoreFlags: Integer;
    38833884begin
    38843885  MoreFlags := SetFlags and not GTestFlags;
     
    38953896          begin // make p1 and p2 know each other
    38963897            if RW[p1].Treaty[p2] = trNoContact then
    3897               IntroduceEnemy(p1, p2)
     3898              IntroduceEnemy(p1, p2);
    38983899          end;
    38993900
     
    39043905      if 1 shl p1 and GAlive <> 0 then
    39053906      begin
    3906         for i := 0 to nAdv - 1 do // give all techs to player p1
    3907           if not(i in FutureTech) and (RW[p1].Tech[i] < tsApplicable) then
     3907        for I := 0 to nAdv - 1 do // give all techs to player p1
     3908          if not(I in FutureTech) and (RW[p1].Tech[I] < tsApplicable) then
    39083909          begin
    3909             RW[p1].Tech[i] := tsCheat;
    3910             CheckSpecialModels(p1, i);
     3910            RW[p1].Tech[I] := tsCheat;
     3911            CheckSpecialModels(p1, I);
    39113912          end;
    39123913        for p2 := 0 to nPl - 1 do
    39133914          if (p2 <> p1) and (1 shl p2 and (GAlive or GWatching) <> 0) then
    3914             for i := 1 to 3 do
    3915               if RW[p2].EnemyReport[p1].Tech[AgePreq[i]] < tsApplicable then
    3916                 RW[p2].EnemyReport[p1].Tech[AgePreq[i]] := tsCheat;
     3915            for I := 1 to 3 do
     3916              if RW[p2].EnemyReport[p1].Tech[AgePreq[I]] < tsApplicable then
     3917                RW[p2].EnemyReport[p1].Tech[AgePreq[I]] := tsCheat;
    39173918      end;
    39183919    end;
     
    39203921  if MoreFlags and tfUncover <> 0 then
    39213922  begin
    3922     DiscoverAll(p, lObserveSuper);
     3923    DiscoverAll(P, lObserveSuper);
    39233924    for p1 := 0 to nPl - 1 do
    39243925      if 1 shl p1 and GAlive <> 0 then
    39253926      begin
    39263927        ResourceMask[p1] := $FFFFFFFF;
    3927         if p1 <> p then
    3928         begin
    3929           GiveCivilReport(p, p1);
    3930           GiveMilReport(p, p1);
     3928        if p1 <> P then
     3929        begin
     3930          GiveCivilReport(P, p1);
     3931          GiveMilReport(P, p1);
    39313932        end;
    39323933      end;
     
    39383939  ____________________________________________________________________
    39393940}
    3940 procedure IntServer(Command, Player, Subject: integer; var Data);
    3941 var
    3942   i, p1: integer;
    3943 
     3941procedure IntServer(Command, Player, Subject: Integer; var Data);
     3942var
     3943  I, p1: Integer;
    39443944begin
    39453945  if Mode = moPlaying then
     
    39513951      begin
    39523952{$IFDEF TEXTLOG}CmdInfo := Format('IntTellAboutNation P%d+P%d', [Player, Subject]); {$ENDIF}
    3953         assert((Player >= 0) and (Player < nPl) and (Subject >= 0) and
     3953        Assert((Player >= 0) and (Player < nPl) and (Subject >= 0) and
    39543954          (Subject < nPl));
    39553955        IntroduceEnemy(Player, Subject);
     
    39593959      begin
    39603960{$IFDEF TEXTLOG}CmdInfo := Format('IntHaveContact P%d+P%d', [Player, Subject]); {$ENDIF}
    3961         assert(RW[Player].Treaty[Subject] > trNoContact);
     3961        Assert(RW[Player].Treaty[Subject] > trNoContact);
    39623962        RW[Player].EnemyReport[Subject].TurnOfContact := GTurn;
    39633963        RW[Subject].EnemyReport[Player].TurnOfContact := GTurn;
     
    39813981        p1 := (Command - sIntTellAboutModel) shr 4; // told player
    39823982{$IFDEF TEXTLOG}CmdInfo := Format('IntTellAboutModel P%d about P%d Mod%d', [p1, Player, Subject]); {$ENDIF}
    3983         assert((Player >= 0) and (Player < nPl));
    3984         assert((Subject >= 0) and (Subject < RW[Player].nModel));
     3983        Assert((Player >= 0) and (Player < nPl));
     3984        Assert((Subject >= 0) and (Subject < RW[Player].nModel));
    39853985        MakeModelInfo(Player, Subject, RW[Player].Model[Subject],
    39863986          RW[p1].EnemyModel[RW[p1].nEnemyModel]);
    39873987        RWemix[p1, Player, Subject] := RW[p1].nEnemyModel;
    3988         inc(RW[p1].nEnemyModel);
    3989         assert(RW[p1].nEnemyModel < nemmax);
     3988        Inc(RW[p1].nEnemyModel);
     3989        Assert(RW[p1].nEnemyModel < nemmax);
    39903990      end;
    39913991
    39923992    sIntDiscoverZOC:
    39933993      begin
    3994 {$IFDEF TEXTLOG}CmdInfo := Format('IntDiscoverZOC P%d Loc%d', [Player, integer(Data)]); {$ENDIF}
    3995         Discover9(integer(Data), Player, lObserveUnhidden, true, false);
     3994{$IFDEF TEXTLOG}CmdInfo := Format('IntDiscoverZOC P%d Loc%d', [Player, Integer(Data)]); {$ENDIF}
     3995        Discover9(Integer(Data), Player, lObserveUnhidden, True, False);
    39963996      end;
    39973997
     
    40004000      begin
    40014001{$IFDEF TEXTLOG}CmdInfo := Format('IntExpandTerritory P%d Loc%d', [Player, RW[Player].City[Subject].Loc]); {$ENDIF}
    4002         move(Data, BorderChanges, SizeOf(BorderChanges));
     4002        Move(Data, BorderChanges, SizeOf(BorderChanges));
    40034003        ExpandTerritory(RW[Player].City[Subject].Loc);
    40044004      end;
     
    40074007      with RW[Player].City[Subject] do
    40084008      begin
    4009 {$IFDEF TEXTLOG}CmdInfo := Format('IntBuyMaterial P%d Loc%d Cost%d', [Player, Loc, integer(Data)]); {$ENDIF}
    4010         dec(RW[Player].Money, integer(Data));
     4009{$IFDEF TEXTLOG}CmdInfo := Format('IntBuyMaterial P%d Loc%d Cost%d', [Player, Loc, Integer(Data)]); {$ENDIF}
     4010        Dec(RW[Player].Money, Integer(Data));
    40114011        if (GWonder[woMich].EffectiveOwner = Player) and (Project and cpImp <> 0)
    40124012        then
    4013           inc(Prod, integer(Data) div 2)
     4013          Inc(Prod, Integer(Data) div 2)
    40144014        else
    4015           inc(Prod, integer(Data) div 4);
     4015          Inc(Prod, Integer(Data) div 4);
    40164016        if Project0 and not cpAuto <> Project and not cpAuto then
    40174017          Project0 := Project;
     
    40224022      begin
    40234023{$IFDEF TEXTLOG}CmdInfo := Format('IntPayPrices P%d+P%d', [Player, Subject]); {$ENDIF}
    4024         for i := 0 to TOffer(Data).nDeliver - 1 do
    4025           PayPrice(Player, Subject, TOffer(Data).Price[i], true);
    4026         for i := 0 to TOffer(Data).nCost - 1 do
     4024        for I := 0 to TOffer(Data).nDeliver - 1 do
     4025          PayPrice(Player, Subject, TOffer(Data).Price[I], True);
     4026        for I := 0 to TOffer(Data).nCost - 1 do
    40274027          PayPrice(Subject, Player, TOffer(Data).Price[TOffer(Data).nDeliver
    4028             + i], true);
    4029         for i := 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do
    4030           if TOffer(Data).Price[i] = opTreaty + trAlliance then
     4028            + I], True);
     4029        for I := 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do
     4030          if TOffer(Data).Price[I] = opTreaty + trAlliance then
    40314031          begin // add view area of allied player
    40324032            DiscoverViewAreas(Player);
    40334033            DiscoverViewAreas(Subject);
    4034             Break
    4035           end
     4034            Break;
     4035          end;
    40364036      end;
    40374037
    40384038    sIntSetDevModel:
    40394039      if Mode < moPlaying then
    4040         move(Data, RW[Player].DevModel.Kind, sIntSetDevModel and $F * 4);
     4040        Move(Data, RW[Player].DevModel.Kind, sIntSetDevModel and $F * 4);
    40414041
    40424042    sIntSetModelStatus:
     
    40454045{$IFDEF TEXTLOG}CmdInfo := Format('IntSetModelStatus P%d', [Player]);
    40464046        {$ENDIF}
    4047         RW[Player].Model[Subject].Status := integer(Data);
     4047        RW[Player].Model[Subject].Status := Integer(Data);
    40484048      end;
    40494049
     
    40534053{$IFDEF TEXTLOG}CmdInfo := Format('IntSetUnitStatus P%d', [Player]);
    40544054        {$ENDIF}
    4055         RW[Player].Un[Subject].Status := integer(Data);
     4055        RW[Player].Un[Subject].Status := Integer(Data);
    40564056      end;
    40574057
     
    40614061{$IFDEF TEXTLOG}CmdInfo := Format('IntSetCityStatus P%d', [Player]);
    40624062        {$ENDIF}
    4063         RW[Player].City[Subject].Status := integer(Data);
     4063        RW[Player].City[Subject].Status := Integer(Data);
    40644064      end;
    40654065
     
    40694069{$IFDEF TEXTLOG}CmdInfo := Format('IntSetECityStatus P%d', [Player]);
    40704070        {$ENDIF}
    4071         RW[Player].EnemyCity[Subject].Status := integer(Data);
    4072       end;
    4073 
    4074   end; { case command }
    4075 end; { IntServer }
     4071        RW[Player].EnemyCity[Subject].Status := Integer(Data);
     4072      end;
     4073  end;
     4074end;
    40764075
    40774076end.
Note: See TracChangeset for help on using the changeset viewer.