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

Legend:

Unmodified
Added
Removed
  • branches/highdpi/GameServer.pas

    r405 r465  
    77
    88uses
    9   Protocol, Database, dynlibs, Platform, dateutils, fgl, LazFileUtils,
    10   Graphics, UBrain, Global;
     9  Protocol, Database, dynlibs, Platform, dateutils, LazFileUtils, Graphics,
     10  Brain, Global;
    1111
    1212const
     
    4949  // PARAMETERS
    5050  PlayersBrain: TBrains; { brain of the players view }
    51   Difficulty: array [0 .. nPl - 1] of integer absolute Database.Difficulty;
     51  Difficulty: array [0 .. nPl - 1] of Integer absolute Database.Difficulty;
    5252  { difficulty }
    5353
     
    7070
    7171procedure StartNewGame(const Path, FileName, Map: string;
    72   Newlx, Newly, NewLandMass, NewMaxTurn: integer);
    73 function LoadGame(const Path, FileName: string; Turn: integer;
    74   MovieMode: boolean): boolean;
    75 procedure EditMap(const Map: string; Newlx, Newly, NewLandMass: integer);
    76 procedure DirectHelp(Command: integer);
     72  Newlx, Newly, NewLandMass, NewMaxTurn: Integer);
     73function LoadGame(const Path, FileName: string; Turn: Integer;
     74  MovieMode: Boolean): Boolean;
     75procedure EditMap(const Map: string; Newlx, Newly, NewLandMass: Integer);
     76procedure DirectHelp(Command: Integer);
    7777
    7878procedure ChangeClient;
    7979procedure NextPlayer;
    80 function PreviewMap(lm: integer): pointer;
     80function PreviewMap(lm: Integer): Pointer;
    8181
    8282
     
    112112  MapField: ^Cardinal; // predefined map
    113113  LastOffer: TOffer;
    114   CCData: array [0 .. 14] of integer;
     114  CCData: array [0 .. 14] of Integer;
    115115  bix: TBrains; { brain of the players }
    116116  DevModelTurn: array [0 .. nPl - 1] of Integer; { turn of last call to sResetModel }
    117117  OriginalDataVersion: array [0 .. nPl - 1] of Integer;
    118118  SavedTiles { , SavedResourceWeights } : array [0 .. ncmax - 1] of Cardinal;
    119   SavedData: array [0 .. nPl - 1] of pointer;
     119  SavedData: array [0 .. nPl - 1] of Pointer;
    120120  LogFileName: string;
    121121  SavePath: string; { name of file for saving the current game }
     
    135135  PreviewRND = 41601260; { randseed for preview map }
    136136
    137 function Server(Command, Player, Subject: integer; var Data): integer;
     137function Server(Command, Player, Subject: Integer; var Data): Integer;
    138138  stdcall; forward;
    139139
    140 procedure CallPlayer(Command, p: integer; var Data);
     140procedure CallPlayer(Command, P: Integer; var Data);
    141141begin
    142   if ((Mode <> moMovie) or (p = 0)) then
     142  if ((Mode <> moMovie) or (P = 0)) then
    143143  begin
    144144{$IFOPT O-}
    145     HandoverStack[nHandoverStack] := p;
     145    HandoverStack[nHandoverStack] := P;
    146146    HandoverStack[nHandoverStack + 1] := Command;
    147     inc(nHandoverStack, 2);
    148     bix[p].Client(Command, p, Data);
    149     dec(nHandoverStack, 2);
     147    Inc(nHandoverStack, 2);
     148    bix[P].Client(Command, P, Data);
     149    Dec(nHandoverStack, 2);
    150150{$ELSE}
    151151    try
    152       bix[p].Client(Command, p, Data);
     152      bix[P].Client(Command, P, Data);
    153153    except
    154       Notify(ntException + bix[p]);
     154      Notify(ntException + bix[P]);
    155155    end;
    156156{$ENDIF}
    157   end
     157  end;
    158158end;
    159159
     
    167167end;
    168168
    169 procedure CallClient(bix, Command: integer; var Data);
     169procedure CallClient(bix, Command: Integer; var Data);
    170170begin
    171171  if ((Mode <> moMovie) or (bix = Brains.IndexOf(GameServer.bix[0]))) then
     
    174174    HandoverStack[nHandoverStack] := bix;
    175175    HandoverStack[nHandoverStack + 1] := Command;
    176     inc(nHandoverStack, 2);
     176    Inc(nHandoverStack, 2);
    177177    Brains[bix].Client(Command, -1, Data);
    178     dec(nHandoverStack, 2);
     178    Dec(nHandoverStack, 2);
    179179{$ELSE}
    180180    try
     
    189189procedure Init(NotifyFunction: TNotifyFunction);
    190190var
    191   f: TSearchRec;
     191  F: TSearchRec;
    192192  BasePath: string;
    193193  NewBrain: TBrain;
     
    195195begin
    196196  Notify := NotifyFunction;
    197   PreviewElevation := false;
     197  PreviewElevation := False;
    198198  PlayersBrain := TBrains.Create(False);
    199199  PlayersBrain.Count := nPl;
     
    246246  end;
    247247
    248   if FindFirst(GetAiDir + DirectorySeparator + '*', faDirectory or faArchive or faReadOnly, f) = 0 then
     248  if FindFirst(GetAiDir + DirectorySeparator + '*', faDirectory or faArchive or faReadOnly, F) = 0 then
    249249  repeat
    250     BasePath := GetAiDir + DirectorySeparator + f.Name;
    251     if (f.Name <> '.') and (f.Name <> '..') and DirectoryExists(BasePath) then begin
     250    BasePath := GetAiDir + DirectorySeparator + F.Name;
     251    if (F.Name <> '.') and (F.Name <> '..') and DirectoryExists(BasePath) then begin
    252252      NewBrain := Brains.AddNew;
    253253      NewBrain.Kind := btAI;
     
    258258        end else Brains.Delete(Brains.Count - 1);
    259259    end;
    260   until FindNext(f) <> 0;
     260  until FindNext(F) <> 0;
    261261  FindClose(F);
    262262
     
    281281end;
    282282
    283 function PreviewMap(lm: integer): pointer;
     283function PreviewMap(lm: Integer): Pointer;
    284284begin
    285285  lx := lxmax;
     
    291291  begin
    292292    CreateElevation;
    293     PreviewElevation := true;
     293    PreviewElevation := True;
    294294  end;
    295   CreateMap(true);
     295  CreateMap(True);
    296296  Result := @RealMap;
    297297end;
    298298
    299 procedure ChangeClientWhenDone(Command, Player: integer; var Data;
    300   DataSize: integer);
     299procedure ChangeClientWhenDone(Command, Player: Integer; var Data;
     300  DataSize: Integer);
    301301begin
    302302  CCCommand := Command;
    303303  CCPlayer := Player;
    304304  if DataSize > 0 then
    305     move(Data, CCData, DataSize);
     305    Move(Data, CCData, DataSize);
    306306  Notify(ntChangeClient);
    307307end;
    308308
    309 procedure PutMessage(Level: integer; Text: string);
     309procedure PutMessage(Level: Integer; Text: string);
    310310begin
    311   bix[0].Client(cDebugMessage, Level, pchar(Text)^);
     311  bix[0].Client(cDebugMessage, Level, PChar(Text)^);
    312312end;
    313313
     
    336336// hand over control to other client (as specified by CC...)
    337337var
    338   p: integer;
     338  P: Integer;
    339339  T: TDateTime;
    340340begin
     
    346346    [CCPlayer, bix[CCPlayer].Name]));
    347347  if CCCommand = cTurn then
    348     for p := 0 to nPl - 1 do
    349       if (p <> CCPlayer) and (1 shl p and GWatching <> 0) then
    350         CallPlayer(cShowTurnChange, p, CCPlayer);
    351 
    352   p := CCPlayer;
     348    for P := 0 to nPl - 1 do
     349      if (P <> CCPlayer) and (1 shl P and GWatching <> 0) then
     350        CallPlayer(cShowTurnChange, P, CCPlayer);
     351
     352  P := CCPlayer;
    353353  CCPlayer := -1;
    354   CallPlayer(CCCommand, p, CCData);
    355   if (Mode = moPlaying) and (bix[p].Flags and aiThreaded = 0) and
     354  CallPlayer(CCCommand, P, CCData);
     355  if (Mode = moPlaying) and (bix[P].Flags and aiThreaded = 0) and
    356356    (CCPlayer < 0) then
    357357  begin
    358     Notify(ntDeactivationMissing, p);
     358    Notify(ntDeactivationMissing, P);
    359359    ForceClientDeactivation;
    360360  end;
    361361end;
    362362
    363 procedure Inform(p: integer);
     363procedure Inform(P: Integer);
    364364var
    365   i, p1: integer;
     365  I, p1: Integer;
    366366begin
    367   RW[p].Turn := GTurn;
    368   if (GTurn = MaxTurn) and (p = pTurn) and (p = 0) then
    369     RW[p].Happened := RW[p].Happened or phTimeUp;
    370   if (GWinner > 0) and (p = pTurn) and (p = 0) then
    371     RW[p].Happened := RW[p].Happened or phShipComplete;
    372   RW[p].Alive := GAlive;
    373   move(GWonder, RW[p].Wonder, SizeOf(GWonder));
    374   move(GShip, RW[p].Ship, SizeOf(GShip));
     367  RW[P].Turn := GTurn;
     368  if (GTurn = MaxTurn) and (P = pTurn) and (P = 0) then
     369    RW[P].Happened := RW[P].Happened or phTimeUp;
     370  if (GWinner > 0) and (P = pTurn) and (P = 0) then
     371    RW[P].Happened := RW[P].Happened or phShipComplete;
     372  RW[P].Alive := GAlive;
     373  Move(GWonder, RW[P].Wonder, SizeOf(GWonder));
     374  Move(GShip, RW[P].Ship, SizeOf(GShip));
    375375  for p1 := 0 to nPl - 1 do
    376     if (p1 <> p) and Assigned(bix[p1]) and (Difficulty[p1] > 0) then
    377       RW[p].EnemyReport[p1].Credibility := RW[p1].Credibility;
     376    if (p1 <> P) and Assigned(bix[p1]) and (Difficulty[p1] > 0) then
     377      RW[P].EnemyReport[p1].Credibility := RW[p1].Credibility;
    378378  for p1 := 0 to nPl - 1 do
    379     if (p1 <> p) and (1 shl p1 and GAlive <> 0) then
     379    if (p1 <> P) and (1 shl p1 and GAlive <> 0) then
    380380    begin
    381       if (GTestFlags and tfUncover <> 0) or (Difficulty[p] = 0) or
    382         (RW[p].Treaty[p1] >= trFriendlyContact) then
    383         GiveCivilReport(p, p1);
    384       if (GTestFlags and tfUncover <> 0) or (Difficulty[p] = 0) or
    385         (RW[p].Treaty[p1] = trAlliance) then
    386         GiveMilReport(p, p1)
     381      if (GTestFlags and tfUncover <> 0) or (Difficulty[P] = 0) or
     382        (RW[P].Treaty[p1] >= trFriendlyContact) then
     383        GiveCivilReport(P, p1);
     384      if (GTestFlags and tfUncover <> 0) or (Difficulty[P] = 0) or
     385        (RW[P].Treaty[p1] = trAlliance) then
     386        GiveMilReport(P, p1)
    387387    end;
    388   for i := 0 to RW[p].nEnemyModel - 1 do
    389     with RW[p].EnemyModel[i] do
    390       Lost := Destroyed[p, Owner, mix];
     388  for I := 0 to RW[P].nEnemyModel - 1 do
     389    with RW[P].EnemyModel[I] do
     390      Lost := Destroyed[P, Owner, mix];
    391391end;
    392392
    393393procedure LogChanges;
    394394var
    395   p, ix: integer;
     395  P, ix: Integer;
    396396begin
    397   for p := 0 to nPl - 1 do
    398     if (1 shl p and GWatching <> 0) and ProcessClientData[p] then
     397  for P := 0 to nPl - 1 do
     398    if (1 shl P and GWatching <> 0) and ProcessClientData[P] then
    399399    begin
    400400      // log unit status changes
    401       for ix := 0 to RW[p].nUn - 1 do
    402         with RW[p].Un[ix] do
     401      for ix := 0 to RW[P].nUn - 1 do
     402        with RW[P].Un[ix] do
    403403          if (Loc >= 0) and (SavedStatus <> Status) then
    404404          begin
    405             CL.Put(sIntSetUnitStatus, p, ix, @Status);
     405            CL.Put(sIntSetUnitStatus, P, ix, @Status);
    406406            SavedStatus := Status;
    407407          end;
    408408      // log city status changes
    409       for ix := 0 to RW[p].nCity - 1 do
    410         with RW[p].City[ix] do
     409      for ix := 0 to RW[P].nCity - 1 do
     410        with RW[P].City[ix] do
    411411          if (Loc >= 0) and (SavedStatus <> Status) then
    412412          begin
    413             CL.Put(sIntSetCityStatus, p, ix, @Status);
     413            CL.Put(sIntSetCityStatus, P, ix, @Status);
    414414            SavedStatus := Status;
    415415          end;
    416416      // log model status changes
    417       for ix := 0 to RW[p].nModel - 1 do
    418         with RW[p].Model[ix] do
     417      for ix := 0 to RW[P].nModel - 1 do
     418        with RW[P].Model[ix] do
    419419          if SavedStatus <> Status then
    420420          begin
    421             CL.Put(sIntSetModelStatus, p, ix, @Status);
     421            CL.Put(sIntSetModelStatus, P, ix, @Status);
    422422            SavedStatus := Status;
    423423          end;
    424424      // log enemy city status changes
    425       for ix := 0 to RW[p].nEnemyCity - 1 do
    426         with RW[p].EnemyCity[ix] do
     425      for ix := 0 to RW[P].nEnemyCity - 1 do
     426        with RW[P].EnemyCity[ix] do
    427427          if (Loc >= 0) and (SavedStatus <> Status) then
    428428          begin
    429             CL.Put(sIntSetECityStatus, p, ix, @Status);
     429            CL.Put(sIntSetECityStatus, P, ix, @Status);
    430430            SavedStatus := Status;
    431431          end;
    432432      // log data changes
    433       if bix[p].DataSize > 0 then
    434       begin
    435         CL.PutDataChanges(sIntDataChange, p, SavedData[p], RW[p].Data,
    436           bix[p].DataSize);
    437         Move(RW[p].Data^, SavedData[p]^, bix[p].DataSize * 4);
     433      if bix[P].DataSize > 0 then
     434      begin
     435        CL.PutDataChanges(sIntDataChange, P, SavedData[P], RW[P].Data,
     436          bix[P].DataSize);
     437        Move(RW[P].Data^, SavedData[P]^, bix[P].DataSize * 4);
    438438      end;
    439439    end;
     
    442442procedure NoLogChanges;
    443443var
    444   p, ix: integer;
     444  P, ix: Integer;
    445445begin
    446   for p := 0 to nPl - 1 do
    447     if (1 shl p and GWatching <> 0) and ProcessClientData[p] then
     446  for P := 0 to nPl - 1 do
     447    if (1 shl P and GWatching <> 0) and ProcessClientData[P] then
    448448    begin
    449       for ix := 0 to RW[p].nUn - 1 do
    450         with RW[p].Un[ix] do
     449      for ix := 0 to RW[P].nUn - 1 do
     450        with RW[P].Un[ix] do
    451451          SavedStatus := Status;
    452       for ix := 0 to RW[p].nCity - 1 do
    453         with RW[p].City[ix] do
     452      for ix := 0 to RW[P].nCity - 1 do
     453        with RW[P].City[ix] do
    454454          SavedStatus := Status;
    455       for ix := 0 to RW[p].nModel - 1 do
    456         with RW[p].Model[ix] do
     455      for ix := 0 to RW[P].nModel - 1 do
     456        with RW[P].Model[ix] do
    457457          SavedStatus := Status;
    458       for ix := 0 to RW[p].nEnemyCity - 1 do
    459         with RW[p].EnemyCity[ix] do
     458      for ix := 0 to RW[P].nEnemyCity - 1 do
     459        with RW[P].EnemyCity[ix] do
    460460          SavedStatus := Status;
    461       if bix[p].DataSize > 0 then
    462         Move(RW[p].Data^, SavedData[p]^, bix[p].DataSize * 4);
     461      if bix[P].DataSize > 0 then
     462        Move(RW[P].Data^, SavedData[P]^, bix[P].DataSize * 4);
    463463    end;
    464464end;
    465465
    466 function HasChanges(p: integer): boolean;
     466function HasChanges(P: Integer): Boolean;
    467467type
    468468  TDWordList = array [0 .. INFIN] of Cardinal;
    469469  PDWortList = ^TDWordList;
    470470var
    471   ix: integer;
     471  ix: Integer;
    472472begin
    473473  Result := False;
    474   for ix := 0 to RW[p].nUn - 1 do
    475     with RW[p].Un[ix] do
     474  for ix := 0 to RW[P].nUn - 1 do
     475    with RW[P].Un[ix] do
    476476      if (Loc >= 0) and (SavedStatus <> Status) then
    477477        Result := True;
    478   for ix := 0 to RW[p].nCity - 1 do
    479     with RW[p].City[ix] do
     478  for ix := 0 to RW[P].nCity - 1 do
     479    with RW[P].City[ix] do
    480480      if (Loc >= 0) and (SavedStatus <> Status) then
    481481        Result := True;
    482   for ix := 0 to RW[p].nModel - 1 do
    483     with RW[p].Model[ix] do
     482  for ix := 0 to RW[P].nModel - 1 do
     483    with RW[P].Model[ix] do
    484484      if SavedStatus <> Status then
    485485        Result := True;
    486   for ix := 0 to RW[p].nEnemyCity - 1 do
    487     with RW[p].EnemyCity[ix] do
     486  for ix := 0 to RW[P].nEnemyCity - 1 do
     487    with RW[P].EnemyCity[ix] do
    488488      if (Loc >= 0) and (SavedStatus <> Status) then
    489489        Result := True;
    490   if RW[p].Data <> nil then
    491     for ix := 0 to bix[p].DataSize - 1 do
    492       if PDWortList(SavedData[p])[ix] <> PDWortList(RW[p].Data)[ix] then
     490  if RW[P].Data <> nil then
     491    for ix := 0 to bix[P].DataSize - 1 do
     492      if PDWortList(SavedData[P])[ix] <> PDWortList(RW[P].Data)[ix] then
    493493        Result := True;
    494494end;
     
    498498  InitModuleData: TInitModuleData;
    499499begin
    500   assert(bix.Kind <> btSuperVirtual);
     500  Assert(bix.Kind <> btSuperVirtual);
    501501  with bix do begin
    502502    if Initialized then
    503       exit;
     503      Exit;
    504504    if Kind = btAI then
    505505    begin { get client function }
     
    509509      else
    510510      begin
    511         hm := LoadLibrary(pchar(DLLName));
     511        hm := LoadLibrary(PChar(DLLName));
    512512        if hm = 0 then
    513513        begin
     
    525525    if @Client <> nil then
    526526    begin
    527       Initialized := true;
     527      Initialized := True;
    528528      InitModuleData.Server := @Server;
    529529      InitModuleData.DataVersion := 0;
     
    542542procedure SaveMap(FileName: string);
    543543var
    544   i: integer;
     544  I: Integer;
    545545  MapFile: TFileStream;
    546   s: string[255];
     546  S: string[255];
    547547begin
    548548  MapFile := TFileStream.Create(GetMapsDir + DirectorySeparator + FileName,
     
    550550  try
    551551    MapFile.Position := 0;
    552     s := 'cEvoMap'#0;
    553     MapFile.write(s[1], 8); { file id }
    554     i := 0;
    555     MapFile.write(i, 4); { format id }
    556     MapFile.write(MaxTurn, 4);
    557     MapFile.write(lx, 4);
    558     MapFile.write(ly, 4);
    559     MapFile.write(RealMap, MapSize * 4);
     552    S := 'cEvoMap'#0;
     553    MapFile.Write(S[1], 8); { file id }
     554    I := 0;
     555    MapFile.Write(I, 4); { format id }
     556    MapFile.Write(MaxTurn, 4);
     557    MapFile.Write(lx, 4);
     558    MapFile.Write(ly, 4);
     559    MapFile.Write(RealMap, MapSize * 4);
    560560  finally
    561561    FreeAndNil(MapFile);
     
    563563end;
    564564
    565 function LoadMap(FileName: string): boolean;
     565function LoadMap(FileName: string): Boolean;
    566566var
    567   i, Loc1: integer;
     567  I, Loc1: Integer;
    568568  MapFile: TFileStream;
    569   s: string[255];
     569  S: string[255];
    570570begin
    571   result := false;
     571  Result := False;
    572572  MapFile := nil;
    573573  try
    574574    MapFile := TFileStream.Create(FileName, fmOpenRead or fmShareExclusive);
    575575    MapFile.Position := 0;
    576     MapFile.read(s[1], 8); { file id }
    577     MapFile.read(i, 4); { format id }
    578     if i = 0 then
     576    MapFile.Read(S[1], 8); { file id }
     577    MapFile.Read(I, 4); { format id }
     578    if I = 0 then
    579579    begin
    580       MapFile.read(i, 4); // MaxTurn
    581       MapFile.read(lx, 4);
    582       MapFile.read(ly, 4);
     580      MapFile.Read(I, 4); // MaxTurn
     581      MapFile.Read(lx, 4);
     582      MapFile.Read(ly, 4);
    583583      ly := ly and not 1;
    584584      if lx > lxmax then
     
    587587        ly := lymax;
    588588      MapSize := lx * ly;
    589       MapFile.read(RealMap, MapSize * 4);
     589      MapFile.Read(RealMap, MapSize * 4);
    590590      for Loc1 := 0 to MapSize - 1 do
    591591      begin
     
    600600            or fDesert;
    601601      end;
    602       result := true;
     602      Result := True;
    603603    end;
    604604    FreeAndNil(MapFile);
     
    609609end;
    610610
    611 procedure SaveGame(FileName: string; auto: boolean);
     611procedure SaveGame(FileName: string; Auto: Boolean);
    612612var
    613   x, y, i, zero, Tile, nLocal: integer;
     613  X, Y, I, zero, Tile, nLocal: Integer;
    614614  LogFile: TFileStream;
    615   s: string[255];
     615  S: string[255];
    616616  SaveMap: array [0 .. lxmax * lymax - 1] of Byte;
    617617begin
    618618  nLocal := 0;
    619   for i := 0 to nPl - 1 do
    620     if Assigned(bix[i]) and (bix[i].Kind = btTerm) then
    621       inc(nLocal);
     619  for I := 0 to nPl - 1 do
     620    if Assigned(bix[I]) and (bix[I].Kind = btTerm) then
     621      Inc(nLocal);
    622622  if Difficulty[0] = 0 then
    623623    nLocal := 0;
    624624  if nLocal <= 1 then
    625     for y := 0 to ly - 1 do
    626       for x := 0 to lx - 1 do
    627       begin
    628         Tile := RW[0].Map[(x + SaveMapCenterLoc + lx shr 1) mod lx + lx * y];
    629         SaveMap[x + lx * y] := Tile and fTerrain + Tile and
     625    for Y := 0 to ly - 1 do
     626      for X := 0 to lx - 1 do
     627      begin
     628        Tile := RW[0].Map[(X + SaveMapCenterLoc + lx shr 1) mod lx + lx * Y];
     629        SaveMap[X + lx * Y] := Tile and fTerrain + Tile and
    630630          (fCity or fUnit or fOwned) shr 16;
    631631      end;
    632632
    633   if auto and AutoSaveExists then // append to existing file
     633  if Auto and AutoSaveExists then // append to existing file
    634634    LogFile := TFileStream.Create(SavePath + FileName, fmOpenReadWrite or
    635635      fmShareExclusive)
     
    640640  zero := 0;
    641641  LogFile.Position := 0;
    642   s := 'cEvoBook';
    643   LogFile.write(s[1], 8); { file id }
    644   i := CevoVersion;
    645   LogFile.write(i, 4); { c-evo version }
    646   LogFile.write(ExeInfo.Time, 4);
    647   LogFile.write(lx, 4);
    648   LogFile.write(ly, 4);
    649   LogFile.write(LandMass, 4);
     642  S := 'cEvoBook';
     643  LogFile.Write(S[1], 8); { file id }
     644  I := CevoVersion;
     645  LogFile.Write(I, 4); { c-evo version }
     646  LogFile.Write(ExeInfo.Time, 4);
     647  LogFile.Write(lx, 4);
     648  LogFile.Write(ly, 4);
     649  LogFile.Write(LandMass, 4);
    650650  if LandMass = 0 then
    651     LogFile.write(MapField^, MapSize * 4);
    652 
    653   LogFile.write(MaxTurn, 4);
    654   LogFile.write(RND, 4);
    655   LogFile.write(GTurn, 4);
     651    LogFile.Write(MapField^, MapSize * 4);
     652
     653  LogFile.Write(MaxTurn, 4);
     654  LogFile.Write(RND, 4);
     655  LogFile.Write(GTurn, 4);
    656656  if nLocal > 1 then // multiplayer game -- no quick view
    657657  begin
    658     i := $80;
    659     LogFile.write(i, 4);
     658    I := $80;
     659    LogFile.Write(I, 4);
    660660  end
    661661  else
    662     LogFile.write(SaveMap, ((MapSize - 1) div 4 + 1) * 4);
    663   for i := 0 to nPl - 1 do
    664     if not Assigned(bix[i]) then
    665       LogFile.write(zero, 4)
     662    LogFile.Write(SaveMap, ((MapSize - 1) div 4 + 1) * 4);
     663  for I := 0 to nPl - 1 do
     664    if not Assigned(bix[I]) then
     665      LogFile.Write(zero, 4)
    666666    else
    667667    begin
    668       if PlayersBrain[i].Kind in [btRandom, btAI] then
    669         s := bix[i].FileName
    670       else
    671         s := PlayersBrain[i].FileName;
    672       move(zero, s[Length(s) + 1], 4);
    673       LogFile.write(s, (Length(s) div 4 + 1) * 4);
    674       LogFile.write(OriginalDataVersion[i], 4);
    675       s := ''; { behavior }
    676       move(zero, s[Length(s) + 1], 4);
    677       LogFile.write(s, (Length(s) div 4 + 1) * 4);
    678       LogFile.write(Difficulty[i], 4);
     668      if PlayersBrain[I].Kind in [btRandom, btAI] then
     669        S := bix[I].FileName
     670      else
     671        S := PlayersBrain[I].FileName;
     672      Move(zero, S[Length(S) + 1], 4);
     673      LogFile.Write(S, (Length(S) div 4 + 1) * 4);
     674      LogFile.Write(OriginalDataVersion[I], 4);
     675      S := ''; { behavior }
     676      Move(zero, S[Length(S) + 1], 4);
     677      LogFile.Write(S, (Length(S) div 4 + 1) * 4);
     678      LogFile.Write(Difficulty[I], 4);
    679679    end;
    680680
    681   if auto and AutoSaveExists then
     681  if Auto and AutoSaveExists then
    682682    CL.AppendToFile(LogFile, AutoSaveState)
    683683  else
    684684    CL.SaveToFile(LogFile);
    685685  FreeAndNil(LogFile);
    686   if auto then
     686  if Auto then
    687687  begin
    688688    AutoSaveState := CL.State;
    689     AutoSaveExists := true;
     689    AutoSaveExists := True;
    690690  end
    691691end;
     
    693693procedure StartGame;
    694694var
    695   i, p, p1, Human, nAlive, bixUni: integer;
     695  I, P, p1, Human, nAlive, bixUni: Integer;
    696696  Game: TNewGameData;
    697697  // GameEx: TNewGameExData;
     
    722722
    723723  BrainUsed := [];
    724   for p := 0 to nPl - 1 do
    725     if Assigned(bix[p]) and ((Mode <> moMovie) or (p = 0)) then
     724  for P := 0 to nPl - 1 do
     725    if Assigned(bix[P]) and ((Mode <> moMovie) or (P = 0)) then
    726726    begin { initiate selected control module }
    727       AIInfo[p] := bix[p].Name + #0;
    728       InitBrain(bix[p]);
     727      AIInfo[P] := bix[P].Name + #0;
     728      InitBrain(bix[P]);
    729729      if Mode = moPlaying then
    730730      begin // new game, this data version is original
    731         OriginalDataVersion[p] := bix[p].DataVersion;
    732         ProcessClientData[p] := true;
     731        OriginalDataVersion[P] := bix[P].DataVersion;
     732        ProcessClientData[P] := True;
    733733      end
    734734      else // loading game, compare with data version read from file
    735         ProcessClientData[p] := ProcessClientData[p] and
    736           (OriginalDataVersion[p] = bix[p].DataVersion);
    737       if @bix[p].Client = nil then // client function not found
     735        ProcessClientData[P] := ProcessClientData[P] and
     736          (OriginalDataVersion[P] = bix[P].DataVersion);
     737      if @bix[P].Client = nil then // client function not found
    738738        if bix[0].Kind = btNoTerm then
    739           bix[p] := nil
     739          bix[P] := nil
    740740        else
    741741        begin
    742           bix[p] := BrainTerm;
    743           OriginalDataVersion[p] := -1;
    744           ProcessClientData[p] := false;
     742          bix[P] := BrainTerm;
     743          OriginalDataVersion[P] := -1;
     744          ProcessClientData[P] := False;
    745745        end;
    746       if Assigned(bix[p]) then
    747         include(BrainUsed, Brains.IndexOf(bix[p]));
     746      if Assigned(bix[P]) then
     747        Include(BrainUsed, Brains.IndexOf(bix[P]));
    748748    end;
    749749
     
    760760    begin
    761761      if Mode <> moMovie then
    762         inc(GWatching, 1 shl p1);
     762        Inc(GWatching, 1 shl p1);
    763763      if bix[p1].Kind = btAI then
    764         inc(GAI, 1 shl p1);
     764        Inc(GAI, 1 shl p1);
    765765      if Difficulty[p1] > 0 then
    766766      begin
    767         inc(GAlive, 1 shl p1);
    768         inc(nAlive);
     767        Inc(GAlive, 1 shl p1);
     768        Inc(nAlive);
    769769      end;
    770770      ServerVersion[p1] := bix[p1].ServerVersion;
     
    779779
    780780  GTurn := 0;
    781   for i := 0 to nWonder - 1 do
    782     with GWonder[i] do
     781  for I := 0 to nWonder - 1 do
     782    with GWonder[I] do
    783783    begin
    784784      CityID := -1;
     
    787787  FillChar(GShip, SizeOf(GShip), 0);
    788788
    789   for p := 0 to nPl - 1 do
    790     if 1 shl p and (GAlive or GWatching) <> 0 then
    791       with RW[p] do
     789  for P := 0 to nPl - 1 do
     790    if 1 shl P and (GAlive or GWatching) <> 0 then
     791      with RW[P] do
    792792      begin
    793793        Government := gDespotism;
     
    799799        AnarchyStart := -AnarchyTurns - 1;
    800800        Happened := 0;
    801         LastValidStat[p] := -1;
    802         Worked[p] := 0;
    803         Founded[p] := 0;
    804         DevModelTurn[p] := -1;
     801        LastValidStat[P] := -1;
     802        Worked[P] := 0;
     803        Founded[P] := 0;
     804        DevModelTurn[P] := -1;
    805805        OracleIncome := 0;
    806806
    807         if bix[p].DataSize > 0 then
     807        if bix[P].DataSize > 0 then
    808808        begin
    809           GetMem(SavedData[p], bix[p].DataSize * 4);
    810           GetMem(Data, bix[p].DataSize * 4);
    811           FillChar(SavedData[p]^, bix[p].DataSize * 4, 0);
    812           FillChar(Data^, bix[p].DataSize * 4, 0);
     809          GetMem(SavedData[P], bix[P].DataSize * 4);
     810          GetMem(Data, bix[P].DataSize * 4);
     811          FillChar(SavedData[P]^, bix[P].DataSize * 4, 0);
     812          FillChar(Data^, bix[P].DataSize * 4, 0);
    813813        end
    814814        else
    815815        begin
    816816          Data := nil;
    817           SavedData[p] := nil
     817          SavedData[P] := nil;
    818818        end;
    819819        nBattleHistory := 0;
     
    825825          end
    826826          else } BorderHelper := nil;
    827         for i := 0 to nStat - 1 do
    828           GetMem(Stat[i, p], 4 * (MaxTurn + 1));
    829         if bix[p].Flags and fDotNet <> 0 then
     827        for I := 0 to nStat - 1 do
     828          GetMem(Stat[I, P], 4 * (MaxTurn + 1));
     829        if bix[P].Flags and fDotNet <> 0 then
    830830        begin
    831           GetMem(RW[p].DefaultDebugMap, MapSize * 4);
    832           FillChar(RW[p].DefaultDebugMap^, MapSize * 4, 0);
    833           DebugMap[p] := RW[p].DefaultDebugMap;
     831          GetMem(RW[P].DefaultDebugMap, MapSize * 4);
     832          FillChar(RW[P].DefaultDebugMap^, MapSize * 4, 0);
     833          DebugMap[P] := RW[P].DefaultDebugMap;
    834834        end
    835835        else
    836           RW[p].DefaultDebugMap := nil;
    837 
    838         { !!!for i:=0 to nShipPart-1 do GShip[p].Parts[i]:=Delphirandom((3-i)*2);{ }
     836          RW[P].DefaultDebugMap := nil;
     837
     838        { !!!for i:=0 to nShipPart-1 do GShip[p].Parts[i]:=Delphirandom((3-i)*2); }
    839839      end;
    840840
     
    842842  begin // random map
    843843    InitRandomGame;
    844     PreviewElevation := false;
     844    PreviewElevation := False;
    845845    MapField := nil;
    846846  end
     
    850850      LoadMap(MapFileName); // new game -- load map from file
    851851    GetMem(MapField, MapSize * 4);
    852     move(RealMap, MapField^, MapSize * 4);
     852    Move(RealMap, MapField^, MapSize * 4);
    853853    Human := 0;
    854854    for p1 := 0 to nPl - 1 do
    855855      if Assigned(bix[p1]) and (bix[p1].Kind = btTerm) then
    856         inc(Human, 1 shl p1);
     856        Inc(Human, 1 shl p1);
    857857    InitMapGame(Human);
    858858  end;
    859859  CityProcessing.InitGame;
    860860  UnitProcessing.InitGame;
    861   for p := 0 to nPl - 1 do
    862     if 1 shl p and (GAlive or GWatching) <> 0 then
    863       Inform(p);
     861  for P := 0 to nPl - 1 do
     862    if 1 shl P and (GAlive or GWatching) <> 0 then
     863      Inform(P);
    864864
    865865  pTurn := -1;
     
    870870  Game.LandMass := LandMass;
    871871  Game.MaxTurn := MaxTurn;
    872   move(Difficulty, Game.Difficulty, SizeOf(Difficulty));
     872  Move(Difficulty, Game.Difficulty, SizeOf(Difficulty));
    873873  // GameEx.lx:=lx; GameEx.ly:=ly; GameEx.LandMass:=LandMass;
    874874  // GameEx.MaxTurn:=MaxTurn; GameEx.RND:=RND;
    875875  // move(Difficulty,GameEx.Difficulty,SizeOf(Difficulty));
    876876  AICredits := '';
    877   for i := 0 to Brains.Count - 1 do
     877  for I := 0 to Brains.Count - 1 do
    878878  with Brains[I] do begin
    879879    if Initialized then
    880       if i in BrainUsed then
     880      if I in BrainUsed then
    881881      begin
    882882        if Kind = btAI then
    883883          Notify(ntInitPlayers);
    884         for p := 0 to nPl - 1 do
     884        for P := 0 to nPl - 1 do
    885885        begin
    886           if Brains.IndexOf(bix[p]) = i then
    887             Game.RO[p] := @RW[p]
     886          if Brains.IndexOf(bix[P]) = I then
     887            Game.RO[P] := @RW[P]
    888888          else
    889             Game.RO[p] := nil;
    890           if (Kind = btTerm) and (Difficulty[0] = 0) and Assigned(bix[p]) then
    891             Game.SuperVisorRO[p] := @RW[p]
     889            Game.RO[P] := nil;
     890          if (Kind = btTerm) and (Difficulty[0] = 0) and Assigned(bix[P]) then
     891            Game.SuperVisorRO[P] := @RW[P]
    892892          else
    893             Game.SuperVisorRO[p] := nil;
     893            Game.SuperVisorRO[P] := nil;
    894894        end;
    895895        if Flags and fDotNet > 0 then
    896896        begin
    897897          Path := DLLName;
    898           move(Path[1], Game.AssemblyPath, Length(Path));
     898          Move(Path[1], Game.AssemblyPath, Length(Path));
    899899          Game.AssemblyPath[Length(Path)] := #0;
    900900        end
     
    903903        case Mode of
    904904          moLoading, moLoading_Fast:
    905             CallClient(i, cLoadGame, Game);
     905            CallClient(I, cLoadGame, Game);
    906906          moMovie:
    907             CallClient(i, cMovie, Game);
     907            CallClient(I, cMovie, Game);
    908908          moPlaying:
    909             CallClient(i, cNewGame, Game);
     909            CallClient(I, cNewGame, Game);
    910910        end;
    911911        if (Kind = btAI) and (Credits <> '') then
     
    917917      else
    918918      begin { module no longer used -- unload }
    919         CallClient(i, cReleaseModule, nil^);
     919        CallClient(I, cReleaseModule, nil^);
    920920        if Kind = btAI then
    921921        begin
     
    924924          Client := nil;
    925925        end;
    926         Initialized := false;
     926        Initialized := False;
    927927      end;
    928928  end;
     
    952952  CheckBorders(-1);
    953953{$IFOPT O-}InvalidTreatyMap := 0; {$ENDIF}
    954   AutoSaveExists := false;
     954  AutoSaveExists := False;
    955955  pDipActive := -1;
    956956  pTurn := 0;
     
    958958  if Mode >= moMovie then
    959959    Notify(ntEndInfo);
    960 end; { StartGame }
     960end;
    961961
    962962procedure EndGame;
    963963var
    964   i, p1: integer;
     964  I, p1: Integer;
    965965begin
    966966  if LandMass = 0 then
     
    969969    if Assigned(bix[p1]) then
    970970    begin
    971       for i := 0 to nStat - 1 do
    972         FreeMem(Stat[i, p1]);
     971      for I := 0 to nStat - 1 do
     972        FreeMem(Stat[I, p1]);
    973973      if RW[p1].BattleHistory <> nil then
    974974        FreeMem(RW[p1].BattleHistory);
     
    985985end;
    986986
    987 procedure GenerateStat(p: integer);
     987procedure GenerateStat(P: Integer);
    988988var
    989   cix, uix: integer;
     989  cix, uix: Integer;
    990990begin
    991   if Difficulty[p] > 0 then
    992     with RW[p] do
     991  if Difficulty[P] > 0 then
     992    with RW[P] do
    993993    begin
    994       Stat[stPop, p, GTurn] := 0;
     994      Stat[stPop, P, GTurn] := 0;
    995995      for cix := 0 to nCity - 1 do
    996996        if City[cix].Loc >= 0 then
    997           inc(Stat[stPop, p, GTurn], City[cix].Size);
    998       Stat[stScience, p, GTurn] := Researched[p] * 50;
    999       if (RW[p].ResearchTech >= 0) and (RW[p].ResearchTech <> adMilitary) then
    1000         inc(Stat[stScience, p, GTurn], Research * 100 div TechBaseCost(nTech[p],
    1001           Difficulty[p]));
    1002       Stat[stMil, p, GTurn] := 0;
     997          Inc(Stat[stPop, P, GTurn], City[cix].Size);
     998      Stat[stScience, P, GTurn] := Researched[P] * 50;
     999      if (RW[P].ResearchTech >= 0) and (RW[P].ResearchTech <> adMilitary) then
     1000        Inc(Stat[stScience, P, GTurn], Research * 100 div TechBaseCost(nTech[P],
     1001          Difficulty[P]));
     1002      Stat[stMil, P, GTurn] := 0;
    10031003      for uix := 0 to nUn - 1 do
    10041004        if Un[uix].Loc >= 0 then
     
    10061006          begin
    10071007            if (Kind <= mkEnemyDeveloped) and (Un[uix].mix <> 1) then
    1008               inc(Stat[stMil, p, GTurn], Weight * MStrength *
     1008              Inc(Stat[stMil, P, GTurn], Weight * MStrength *
    10091009                Un[uix].Health div 100)
    10101010            else if Domain = dGround then
    1011               inc(Stat[stMil, p, GTurn], (Attack + 2 * Defense) *
     1011              Inc(Stat[stMil, P, GTurn], (Attack + 2 * Defense) *
    10121012                Un[uix].Health div 100)
    10131013            else
    1014               inc(Stat[stMil, p, GTurn], (Attack + Defense) *
     1014              Inc(Stat[stMil, P, GTurn], (Attack + Defense) *
    10151015                Un[uix].Health div 100);
    10161016            case Kind of
    10171017              mkSlaves:
    1018                 inc(Stat[stPop, p, GTurn]);
     1018                Inc(Stat[stPop, P, GTurn]);
    10191019              mkSettler:
    1020                 inc(Stat[stPop, p, GTurn], 2);
     1020                Inc(Stat[stPop, P, GTurn], 2);
    10211021            end;
    10221022          end;
    1023       Stat[stMil, p, GTurn] := Stat[stMil, p, GTurn] div 16;
    1024       Stat[stExplore, p, GTurn] := Discovered[p];
    1025       Stat[stTerritory, p, GTurn] := TerritoryCount[p];
    1026       Stat[stWork, p, GTurn] := Worked[p];
    1027       LastValidStat[p] := GTurn;
     1023      Stat[stMil, P, GTurn] := Stat[stMil, P, GTurn] div 16;
     1024      Stat[stExplore, P, GTurn] := Discovered[P];
     1025      Stat[stTerritory, P, GTurn] := TerritoryCount[P];
     1026      Stat[stWork, P, GTurn] := Worked[P];
     1027      LastValidStat[P] := GTurn;
    10281028    end;
    10291029end;
     
    10311031procedure LogCityTileChanges;
    10321032var
    1033   cix: integer;
     1033  cix: Integer;
    10341034begin
    10351035  for cix := 0 to RW[pTurn].nCity - 1 do
     
    10521052procedure NoLogCityTileChanges;
    10531053var
    1054   cix: integer;
     1054  cix: Integer;
    10551055begin
    10561056  for cix := 0 to RW[pTurn].nCity - 1 do
     
    10631063end;
    10641064
    1065 function HasCityTileChanges: boolean;
     1065function HasCityTileChanges: Boolean;
    10661066var
    1067   cix: integer;
     1067  cix: Integer;
    10681068begin
    1069   result := false;
     1069  Result := False;
    10701070  for cix := 0 to RW[pTurn].nCity - 1 do
    10711071    with RW[pTurn].City[cix] do
     
    10741074        // if SavedResourceWeights[cix]<>ResourceWeights then result:=true;
    10751075        if SavedTiles[cix] <> Tiles then
    1076           result := true;
     1076          Result := True;
    10771077      end;
    10781078end;
     
    10801080procedure BeforeTurn0;
    10811081var
    1082   p1, uix: integer;
     1082  p1, uix: Integer;
    10831083begin
    10841084  for uix := 0 to RW[pTurn].nUn - 1 do { init movement points for first turn }
     
    11011101end;
    11021102
    1103 function LoadGame(const Path, FileName: string; Turn: integer;
    1104   MovieMode: boolean): boolean;
     1103function LoadGame(const Path, FileName: string; Turn: Integer;
     1104  MovieMode: Boolean): Boolean;
    11051105var
    11061106  J: TBrain;
    1107   i, ix, d, p1, Command, Subject: integer;
     1107  I, ix, D, p1, Command, Subject: Integer;
    11081108  K: Integer;
    1109 {$IFDEF TEXTLOG}LoadPos0: integer; {$ENDIF}
    1110   Data: pointer;
     1109{$IFDEF TEXTLOG}LoadPos0: Integer; {$ENDIF}
     1110  Data: Pointer;
    11111111  LogFile: TFileStream;
    11121112  FormerCLState: TCmdListState;
    1113   s: string[255];
     1113  S: string[255];
    11141114  SaveMap: array [0 .. lxmax * lymax - 1] of Byte;
    1115   Started, StatRequest: boolean;
     1115  Started, StatRequest: Boolean;
    11161116begin
    11171117  SavePath := Path;
     
    11211121    fmShareExclusive);
    11221122  LogFile.Position := 0;
    1123   LogFile.Read(s[1], 8); { file id }
    1124   LogFile.Read(i, 4); { c-evo version }
     1123  LogFile.Read(S[1], 8); { file id }
     1124  LogFile.Read(I, 4); { c-evo version }
    11251125  LogFile.Read(J, 4); { exe time }
    11261126
    1127   if (i >= FirstBookCompatibleVersion) and (i <= CevoVersion) then
     1127  if (I >= FirstBookCompatibleVersion) and (I <= CevoVersion) then
    11281128  begin
    1129     result := true;
     1129    Result := True;
    11301130    LogFile.Read(lx, 4);
    11311131    LogFile.Read(ly, 4);
     
    11391139    LogFile.Read(SaveMap, 4);
    11401140    if SaveMap[0] <> $80 then
    1141       LogFile.read(SaveMap[4], ((MapSize - 1) div 4 + 1) * 4 - 4);
     1141      LogFile.Read(SaveMap[4], ((MapSize - 1) div 4 + 1) * 4 - 4);
    11421142    for p1 := 0 to nPl - 1 do
    11431143    begin
    1144       LogFile.Read(s[0], 4);
    1145       if s[0] = #0 then
     1144      LogFile.Read(S[0], 4);
     1145      if S[0] = #0 then
    11461146        PlayersBrain[p1] := nil
    11471147      else
    11481148      begin
    1149         LogFile.Read(s[4], Byte(s[0]) div 4 * 4);
     1149        LogFile.Read(S[4], Byte(S[0]) div 4 * 4);
    11501150        LogFile.Read(OriginalDataVersion[p1], 4);
    1151         LogFile.Read(d, 4); { behavior }
     1151        LogFile.Read(D, 4); { behavior }
    11521152        LogFile.Read(Difficulty[p1], 4);
    11531153        J := Brains.Last;
    1154         while Assigned(J) and (AnsiCompareFileName(J.FileName, s) <> 0) do begin
     1154        while Assigned(J) and (AnsiCompareFileName(J.FileName, S) <> 0) do begin
    11551155          K := Brains.IndexOf(J) - 1;
    11561156          if K >= 0 then J := Brains[K]
     
    11591159        if not Assigned(J) then
    11601160        begin // ai not found -- replace by local player
    1161           ProcessClientData[p1] := false;
    1162           NotifyMessage := s;
     1161          ProcessClientData[p1] := False;
     1162          NotifyMessage := S;
    11631163          Notify(ntAIError);
    11641164          J := BrainTerm;
    11651165        end
    11661166        else
    1167           ProcessClientData[p1] := true;
    1168         if j.Kind = btNoTerm then
    1169           j := BrainSuperVirtual;
     1167          ProcessClientData[p1] := True;
     1168        if J.Kind = btNoTerm then
     1169          J := BrainSuperVirtual;
    11701170        // crashed tournament -- load as supervisor
    1171         PlayersBrain[p1] := j;
     1171        PlayersBrain[p1] := J;
    11721172      end;
    11731173    end;
    11741174  end
    11751175  else
    1176     Result := false;
     1176    Result := False;
    11771177
    11781178  if Result then begin
     
    11811181  end;
    11821182  FreeAndNil(LogFile);
    1183   if not result then
     1183  if not Result then
    11841184    Exit;
    11851185
     
    11951195{$IFDEF TEXTLOG}AssignFile(TextLog, SavePath + LogFileName + '.txt');
    11961196  Rewrite(TextLog); {$ENDIF}
    1197   LoadOK := true;
     1197  LoadOK := True;
    11981198  StartGame;
    11991199  if MovieMode then
     
    12051205    Notify(ntLoadBegin);
    12061206
    1207   started := false;
    1208   StatRequest := false;
    1209   MovieStopped := false;
     1207  started := False;
     1208  StatRequest := False;
     1209  MovieStopped := False;
    12101210{$IFDEF LOADPERF}QueryPerformanceCounter(time_total0);
    12111211  time_a := 0;
     
    12221222    begin
    12231223      GenerateStat(pTurn);
    1224       StatRequest := false;
     1224      StatRequest := False;
    12251225    end;
    12261226    // complete all internal commands following an sTurn before generating statistics
     
    12371237        CallPlayer(cMovieTurn, 0, nil^);
    12381238      end;
    1239       StatRequest := true;
    1240       started := true;
     1239      StatRequest := True;
     1240      started := True;
    12411241    end
    12421242    else if (Command = sTurn) and (pTurn = 0) and (GTurn = LoadTurn) then
    12431243    begin
    1244       assert(CL.State.LoadPos = FormerCLState.LoadPos + 4); // size of sTurn
     1244      Assert(CL.State.LoadPos = FormerCLState.LoadPos + 4); // size of sTurn
    12451245      CL.State := FormerCLState;
    12461246      CL.Cut;
     
    12781278    EndGame;
    12791279    Notify(ntStartGo);
    1280     result := false;
    1281     exit;
     1280    Result := False;
     1281    Exit;
    12821282  end;
    12831283
    12841284  if StatRequest then
    12851285    GenerateStat(pTurn);
    1286   assert(started);
     1286  Assert(started);
    12871287{$IFDEF TEXTLOG}CloseFile(TextLog); {$ENDIF}
    12881288{$IFDEF LOADPERF}QueryPerformanceCounter(time_total); { time in s is: (time_total-time_total0)/PerfFreq }{$ENDIF}
     
    13241324  Inform(pTurn);
    13251325  ChangeClientWhenDone(cResume, 0, nil^, 0);
    1326 end; // LoadGame
     1326end;
    13271327
    13281328procedure InsertTerritoryUpdateCommands;
    13291329var
    1330   p1, Command, Subject: integer;
    1331   Data: pointer;
     1330  p1, Command, Subject: Integer;
     1331  Data: Pointer;
    13321332  FormerCLState: TCmdListState;
    13331333begin
     
    13511351
    13521352procedure StartNewGame(const Path, FileName, Map: string;
    1353   Newlx, Newly, NewLandMass, NewMaxTurn: integer);
     1353  Newlx, Newly, NewLandMass, NewMaxTurn: Integer);
    13541354var
    13551355  I: Integer;
     
    13951395end;
    13961396
    1397 procedure DirectHelp(Command: integer);
     1397procedure DirectHelp(Command: Integer);
    13981398begin
    13991399  InitBrain(BrainTerm);
     
    14021402end;
    14031403
    1404 procedure EditMap(const Map: string; Newlx, Newly, NewLandMass: integer);
     1404procedure EditMap(const Map: string; Newlx, Newly, NewLandMass: Integer);
    14051405var
    1406   p1, Loc1: integer;
     1406  p1, Loc1: Integer;
    14071407  Game: TNewGameData;
    14081408begin
     
    14461446end;
    14471447
    1448 procedure DestroySpacePort_TellPlayers(p, pCapturer: integer);
     1448procedure DestroySpacePort_TellPlayers(P, pCapturer: Integer);
    14491449var
    1450   cix, i, p1: integer;
     1450  cix, I, p1: Integer;
    14511451  ShowShipChange: TShowShipChange;
    14521452begin
    14531453  // stop ship part production
    1454   for cix := 0 to RW[p].nCity - 1 do
    1455     with RW[p].City[cix] do
     1454  for cix := 0 to RW[P].nCity - 1 do
     1455    with RW[P].City[cix] do
    14561456      if (Loc >= 0) and (Project and cpImp <> 0) and
    14571457        ((Project and cpIndex = woMIR) or
    14581458        (Imp[Project and cpIndex].Kind = ikShipPart)) then
    14591459      begin
    1460         inc(RW[p].Money, Prod0);
     1460        Inc(RW[P].Money, Prod0);
    14611461        Prod := 0;
    14621462        Prod0 := 0;
     
    14661466
    14671467  // destroy ship
    1468   with GShip[p] do
     1468  with GShip[P] do
    14691469    if Parts[0] + Parts[1] + Parts[2] > 0 then
    14701470    begin
    1471       for i := 0 to nShipPart - 1 do
    1472       begin
    1473         ShowShipChange.Ship1Change[i] := -Parts[i];
     1471      for I := 0 to nShipPart - 1 do
     1472      begin
     1473        ShowShipChange.Ship1Change[I] := -Parts[I];
    14741474        if pCapturer >= 0 then
    14751475        begin
    1476           ShowShipChange.Ship2Change[i] := Parts[i];
    1477           inc(GShip[pCapturer].Parts[i], Parts[i]);
     1476          ShowShipChange.Ship2Change[I] := Parts[I];
     1477          Inc(GShip[pCapturer].Parts[I], Parts[I]);
    14781478        end;
    1479         Parts[i] := 0;
     1479        Parts[I] := 0;
    14801480      end;
    14811481      if Mode >= moMovie then
     
    14851485        else
    14861486          ShowShipChange.Reason := scrDestruction;
    1487         ShowShipChange.Ship1Owner := p;
     1487        ShowShipChange.Ship1Owner := P;
    14881488        ShowShipChange.Ship2Owner := pCapturer;
    14891489        for p1 := 0 to nPl - 1 do
    14901490          if 1 shl p1 and (GAlive or GWatching) <> 0 then
    14911491          begin
    1492             move(GShip, RW[p1].Ship, SizeOf(GShip));
     1492            Move(GShip, RW[p1].Ship, SizeOf(GShip));
    14931493            if 1 shl p1 and GWatching <> 0 then
    14941494              CallPlayer(cShowShipChange, p1, ShowShipChange);
     
    14981498end;
    14991499
    1500 procedure DestroyCity_TellPlayers(p, cix: integer; SaveUnits: boolean);
     1500procedure DestroyCity_TellPlayers(P, cix: Integer; SaveUnits: Boolean);
    15011501begin
    1502   if RW[p].City[cix].built[imSpacePort] > 0 then
    1503     DestroySpacePort_TellPlayers(p, -1);
    1504   DestroyCity(p, cix, SaveUnits);
     1502  if RW[P].City[cix].built[imSpacePort] > 0 then
     1503    DestroySpacePort_TellPlayers(P, -1);
     1504  DestroyCity(P, cix, SaveUnits);
    15051505end;
    15061506
    1507 procedure ChangeCityOwner_TellPlayers(pOld, cixOld, pNew: integer);
     1507procedure ChangeCityOwner_TellPlayers(pOld, cixOld, pNew: Integer);
    15081508begin
    15091509  if RW[pOld].City[cixOld].built[imSpacePort] > 0 then
     
    15151515end;
    15161516
    1517 procedure CheckWin(p: integer);
     1517procedure CheckWin(P: Integer);
    15181518var
    1519   i: integer;
    1520   ShipComplete: boolean;
     1519  I: Integer;
     1520  ShipComplete: Boolean;
    15211521begin
    1522   ShipComplete := true;
    1523   for i := 0 to nShipPart - 1 do
    1524     if GShip[p].Parts[i] < ShipNeed[i] then
    1525       ShipComplete := false;
     1522  ShipComplete := True;
     1523  for I := 0 to nShipPart - 1 do
     1524    if GShip[P].Parts[I] < ShipNeed[I] then
     1525      ShipComplete := False;
    15261526  if ShipComplete then
    1527     GWinner := GWinner or 1 shl p; // game won!
     1527    GWinner := GWinner or 1 shl P; // game won!
    15281528end;
    15291529
    15301530procedure BeforeTurn;
    15311531var
    1532   i, p1, uix, cix, V21, Loc1, Cost, Job0, nAlive, nAppliers, ad, OldLoc,
    1533     SiegedTiles, nUpdateLoc: integer;
    1534   UpdateLoc: array [0 .. numax - 1] of integer;
     1532  I, p1, uix, cix, V21, Loc1, Cost, Job0, nAlive, nAppliers, ad, OldLoc,
     1533    SiegedTiles, nUpdateLoc: Integer;
     1534  UpdateLoc: array [0 .. numax - 1] of Integer;
    15351535  Radius: TVicinity21Loc;
    15361536  ShowShipChange: TShowShipChange;
    1537   TribeExtinct, JobDone, MirBuilt: boolean;
     1537  TribeExtinct, JobDone, MirBuilt: Boolean;
    15381538begin
    1539 {$IFOPT O-}assert(1 shl pTurn and InvalidTreatyMap = 0); {$ENDIF}
    1540   assert(1 shl pTurn and (GAlive or GWatching) <> 0);
     1539{$IFOPT O-}Assert(1 shl pTurn and InvalidTreatyMap = 0); {$ENDIF}
     1540  Assert(1 shl pTurn and (GAlive or GWatching) <> 0);
    15411541  if (1 shl pTurn and GAlive = 0) and (Difficulty[pTurn] > 0) then
    1542     exit;
     1542    Exit;
    15431543
    15441544  if (GWonder[woGrLibrary].EffectiveOwner = pTurn) and (GWinner = 0) then
     
    15471547    for p1 := 0 to nPl - 1 do
    15481548      if 1 shl p1 and GAlive <> 0 then
    1549         inc(nAlive);
     1549        Inc(nAlive);
    15501550    ad := 0;
    15511551    while ad <= (nAdv - 5) do begin
     
    15561556          if (p1 <> pTurn) and (1 shl p1 and GAlive <> 0) and
    15571557            (RW[p1].Tech[ad] >= tsApplicable) then
    1558             inc(nAppliers);
     1558            Inc(nAppliers);
    15591559        if nAppliers * 2 > nAlive then
    15601560        begin
    15611561          SeeTech(pTurn, ad);
    1562           inc(nTech[pTurn]);
     1562          Inc(nTech[pTurn]);
    15631563          if Mode >= moMovie then
    15641564            CallPlayer(cShowGreatLibTech, pTurn, ad);
     
    15771577  RW[pTurn].nEnemyUn := 0;
    15781578
    1579   MirBuilt := false;
     1579  MirBuilt := False;
    15801580  if (Difficulty[pTurn] > 0) and (GWinner = 0) then
    15811581    with RW[pTurn] do
     
    16001600                  begin // transport unload
    16011601                    if Model[mix].Domain = dAir then
    1602                       dec(Un[Master].AirLoad)
     1602                      Dec(Un[Master].AirLoad)
    16031603                    else
    1604                       dec(Un[Master].TroopLoad);
     1604                      Dec(Un[Master].TroopLoad);
    16051605                    Master := -1;
    16061606                  end
     
    16221622      if Mode >= moMovie then
    16231623        FillChar(ShowShipChange, SizeOf(ShowShipChange), 0);
    1624       TribeExtinct := true;
     1624      TribeExtinct := True;
    16251625      nUpdateLoc := 0;
    16261626      for cix := 0 to nCity - 1 do
     
    16381638              begin
    16391639                Loc1 := Radius[V21];
    1640                 assert((Loc1 >= 0) and (Loc1 < MapSize) and
     1640                Assert((Loc1 >= 0) and (Loc1 < MapSize) and
    16411641                  (UsedByCity[Loc1] = Loc));
    16421642                p1 := RealMap[Loc1] shr 27;
     
    16491649                  UsedByCity[Loc1] := -1;
    16501650                  Flags := Flags or chSiege;
    1651                   inc(SiegedTiles);
     1651                  Inc(SiegedTiles);
    16521652                end;
    16531653              end;
     
    16561656              if not AddBestCityTile(pTurn, cix) then
    16571657                Break;
    1658               dec(SiegedTiles);
     1658              Dec(SiegedTiles);
    16591659            end;
    16601660
     
    16641664
    16651665              if CityTurn(pTurn, cix) then
    1666                 TribeExtinct := false
     1666                TribeExtinct := False
    16671667              else
    16681668              begin // city is erased
     
    16711671                Map[Loc] := Map[Loc] and not fCity; // !!! do this in inner core
    16721672                UpdateLoc[nUpdateLoc] := Loc;
    1673                 inc(nUpdateLoc);
    1674                 DestroyCity_TellPlayers(pTurn, cix, true);
     1673                Inc(nUpdateLoc);
     1674                DestroyCity_TellPlayers(pTurn, cix, True);
    16751675              end;
    16761676
     
    16791679              begin
    16801680                if Project0 and cpIndex = woMIR then // MIR completed
    1681                   MirBuilt := true
     1681                  MirBuilt := True
    16821682                else if Project0 and cpIndex = woManhattan then
    16831683                  GColdWarStart := GTurn
    16841684                else if Imp[Project0 and cpIndex].Kind = ikShipPart
    16851685                then { ship parts produced }
    1686                   inc(ShowShipChange.Ship1Change[Project0 and cpIndex -
     1686                  Inc(ShowShipChange.Ship1Change[Project0 and cpIndex -
    16871687                    imShipComp]);
    16881688              end;
     
    16921692      begin
    16931693        CheckBorders(-1, pTurn);
    1694         for i := 0 to nUpdateLoc - 1 do
    1695           UpdateUnitMap(UpdateLoc[i], true);
     1694        for I := 0 to nUpdateLoc - 1 do
     1695          UpdateUnitMap(UpdateLoc[I], True);
    16961696        if Mode >= moMovie then
    16971697          for p1 := 0 to nPl - 1 do
    16981698            if (1 shl p1 and GWatching <> 0) and (p1 <> pTurn) then
    1699               for i := 0 to nUpdateLoc - 1 do
    1700                 if ObserveLevel[UpdateLoc[i]] shr (2 * p1) and 3 >= lObserveUnhidden
     1699              for I := 0 to nUpdateLoc - 1 do
     1700                if ObserveLevel[UpdateLoc[I]] shr (2 * p1) and 3 >= lObserveUnhidden
    17011701                then
    1702                   CallPlayer(cShowCityChanged, p1, UpdateLoc[i]);
     1702                  CallPlayer(cShowCityChanged, p1, UpdateLoc[I]);
    17031703      end;
    17041704
     
    17181718              Movement := UnitSpeed(pTurn, mix, Health); { refresh movement }
    17191719
    1720             assert(Loc >= 0);
     1720            Assert(Loc >= 0);
    17211721            if Model[mix].Kind <> mkDiplomat then
    17221722            begin // check treaty violation
     
    17621762              begin
    17631763                AddBestCityTile(pTurn, RW[pTurn].nCity - 1);
    1764                 UpdateUnitMap(Loc1, true);
     1764                UpdateUnitMap(Loc1, True);
    17651765                if Mode >= moMovie then // tell enemies
    17661766                  for p1 := 0 to nPl - 1 do
     
    18101810            end;
    18111811          end;
    1812         exit
     1812        Exit;
    18131813      end;
    18141814
     
    18241824          DiscoverTech(pTurn, ResearchTech);
    18251825
    1826         dec(Research, Cost);
     1826        Dec(Research, Cost);
    18271827        Happened := Happened or phTech;
    1828         ResearchTech := -1
     1828        ResearchTech := -1;
    18291829      end
    18301830      else if (ResearchTech = -2) and (nCity > 0) then
     
    18391839            (Treaty[p1] >= trPeace) then
    18401840          begin
    1841             inc(Credibility);
     1841            Inc(Credibility);
    18421842            Break;
    18431843          end;
     
    18561856          if (p1 <> pTurn) and (1 shl p1 and (GAlive or GWatching) <> 0) then
    18571857          begin
    1858             move(GShip, RW[p1].Ship, SizeOf(GShip));
     1858            Move(GShip, RW[p1].Ship, SizeOf(GShip));
    18591859            if 1 shl p1 and GWatching <> 0 then
    18601860              CallPlayer(cShowShipChange, p1, ShowShipChange);
    1861           end
     1861          end;
    18621862      end;
    18631863      if WinOnAlone and (GAlive and not(1 shl pTurn or 1) = 0) then
     
    18711871          if (p1 <> pTurn) and ((GAlive or GWatching) and (1 shl p1) <> 0) then
    18721872            RW[p1].EnemyReport[pTurn].Government := gDespotism;
    1873         inc(Happened, phChangeGov)
     1873        Inc(Happened, phChangeGov);
    18741874      end;
    18751875    end; // if Difficulty[pTurn]>0
     
    19081908  end;
    19091909  // CheckContact;
    1910 end; { BeforeTurn }
     1910end;
    19111911
    19121912procedure AfterTurn;
    19131913var
    1914   cix, uix, p1, Loc1, Job0: integer;
    1915   JobDone: boolean;
     1914  cix, uix, p1, Loc1, Job0: Integer;
     1915  JobDone: Boolean;
    19161916begin
    19171917  with RW[pTurn] do
     
    19251925      end;
    19261926
    1927     inc(Money, OracleIncome);
     1927    Inc(Money, OracleIncome);
    19281928    OracleIncome := 0;
    19291929    if GWonder[woOracle].EffectiveOwner = pTurn then
     
    19351935            if (RW[p1].City[cix].Loc >= 0) and
    19361936              (RW[p1].City[cix].built[imTemple] > 0) then
    1937               inc(OracleIncome);
     1937              Inc(OracleIncome);
    19381938    end;
    19391939
     
    19621962            begin
    19631963              AddBestCityTile(pTurn, RW[pTurn].nCity - 1);
    1964               UpdateUnitMap(Loc1, true);
     1964              UpdateUnitMap(Loc1, True);
    19651965              if Mode >= moMovie then // tell enemies
    19661966                for p1 := 0 to nPl - 1 do
     
    19931993            else
    19941994            begin
    1995               dec(Fuel);
     1995              Dec(Fuel);
    19961996              if Fuel < 0 then
    19971997              begin
     
    20132013        Flags := Flags and not unWithdrawn;
    20142014        if (Loc >= 0) and (Model[mix].Domain = dGround) and (Master < 0) and
    2015           ((integer(Movement) = Model[mix].Speed) or
     2015          ((Integer(Movement) = Model[mix].Speed) or
    20162016          (Model[mix].Cap[mcAcademy] > 0) and (Movement * 2 >= Model[mix].Speed))
    20172017        then
     
    20352035          CheckWin(p1);
    20362036  end;
    2037 end; // Afterturn
     2037end;
    20382038
    20392039procedure NextPlayer;
     
    20492049end;
    20502050
    2051 function ExecuteMove(p, uix, ToLoc: integer; var MoveInfo: TMoveInfo;
    2052   ShowMove: TShowMove): integer;
     2051function ExecuteMove(P, uix, ToLoc: Integer; var MoveInfo: TMoveInfo;
     2052  ShowMove: TShowMove): Integer;
    20532053var
    2054   i, p1, FromLoc, uix1, nUpdateLoc: integer;
     2054  I, p1, FromLoc, uix1, nUpdateLoc: Integer;
    20552055  MinLevel, MissionResult: Cardinal;
    20562056  PModel: ^TModel;
    2057   UpdateLoc: array [0 .. numax - 1] of integer;
    2058   SeeFrom, SeeTo, ExtDiscover: boolean;
     2057  UpdateLoc: array [0 .. numax - 1] of Integer;
     2058  SeeFrom, SeeTo, ExtDiscover: Boolean;
    20592059begin
    2060   result := 0;
    2061   with RW[p], Un[uix] do
     2060  Result := 0;
     2061  with RW[P], Un[uix] do
    20622062  begin
    20632063    PModel := @Model[mix];
     
    20652065
    20662066    if Master < 0 then
    2067       FreeUnit(p, uix);
     2067      FreeUnit(P, uix);
    20682068    if (MoveInfo.MoveType in [mtMove, mtCapture]) and MoveInfo.MountainDelay
    20692069    then
     
    20732073    Loc := -2;
    20742074    if TroopLoad + AirLoad > 0 then
    2075       for i := 0 to nUn - 1 do
    2076         if (Un[i].Loc >= 0) and (Un[i].Master = uix) then
    2077           Un[i].Loc := -2;
     2075      for I := 0 to nUn - 1 do
     2076        if (Un[I].Loc >= 0) and (Un[I].Master = uix) then
     2077          Un[I].Loc := -2;
    20782078    UpdateUnitMap(FromLoc);
    20792079
     
    20932093          ShowMove.Flags := ShowMove.Flags or umShipLoading;
    20942094      for p1 := 0 to nPl - 1 do
    2095         if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or (bix[p1].Kind = btTerm))
     2095        if (1 shl p1 and GWatching <> 0) and ((p1 <> P) or (bix[p1].Kind = btTerm))
    20962096        then
    20972097        begin
     
    21022102          else
    21032103            MinLevel := lObserveUnhidden;
    2104           SeeFrom := (p1 = p) or (ObserveLevel[FromLoc] shr (2 * p1) and
     2104          SeeFrom := (p1 = P) or (ObserveLevel[FromLoc] shr (2 * p1) and
    21052105            3 >= MinLevel);
    2106           SeeTo := (p1 = p) or (ObserveLevel[ToLoc] shr (2 * p1) and
     2106          SeeTo := (p1 = P) or (ObserveLevel[ToLoc] shr (2 * p1) and
    21072107            3 >= MinLevel);
    21082108          if SeeFrom and SeeTo then
    21092109          begin
    2110             TellAboutModel(p1, p, mix);
    2111             if p1 = p then
     2110            TellAboutModel(p1, P, mix);
     2111            if p1 = P then
    21122112              ShowMove.emix := -1
    21132113            else
    2114               ShowMove.emix := emixSafe(p1, p, mix);
     2114              ShowMove.emix := emixSafe(p1, P, mix);
    21152115            if MoveInfo.MoveType = mtCapture then
    21162116              CallPlayer(cShowCapturing, p1, ShowMove)
     
    21262126      Loc := ToLoc;
    21272127    if TroopLoad + AirLoad > 0 then
    2128       for i := 0 to nUn - 1 do
    2129         if Un[i].Loc = -2 then
    2130           Un[i].Loc := ToLoc;
    2131 
    2132     ExtDiscover := false;
     2128      for I := 0 to nUn - 1 do
     2129        if Un[I].Loc = -2 then
     2130          Un[I].Loc := ToLoc;
     2131
     2132    ExtDiscover := False;
    21332133    nUpdateLoc := 0;
    21342134    if MoveInfo.MoveType = mtCapture then
    21352135    begin
    2136       assert(Occupant[ToLoc] < 0);
     2136      Assert(Occupant[ToLoc] < 0);
    21372137      for uix1 := 0 to RW[MoveInfo.Defender].nUn - 1 do
    21382138        with RW[MoveInfo.Defender].Un[uix1] do
     
    21402140          begin
    21412141            UpdateLoc[nUpdateLoc] := Loc;
    2142             inc(nUpdateLoc);
     2142            Inc(nUpdateLoc);
    21432143          end;
    21442144      // unit will be removed -- remember position and update for all players
     
    21472147      then
    21482148      begin // city captured
    2149         ChangeCityOwner_TellPlayers(MoveInfo.Defender, MoveInfo.Dcix, p);
     2149        ChangeCityOwner_TellPlayers(MoveInfo.Defender, MoveInfo.Dcix, P);
    21502150        City[nCity - 1].Flags := CaptureTurns shl 16;
    2151         CityShrink(p, nCity - 1);
     2151        CityShrink(P, nCity - 1);
    21522152        if Mode = moPlaying then
    2153           with RW[p].City[nCity - 1] do
     2153          with RW[P].City[nCity - 1] do
    21542154          begin
    21552155            // SavedResourceWeights[nCity-1]:=ResourceWeights;
    21562156            SavedTiles[nCity - 1] := Tiles;
    21572157          end;
    2158         ExtDiscover := true;
     2158        ExtDiscover := True;
    21592159
    21602160        // Temple of Zeus effect
    2161         if GWonder[woZeus].EffectiveOwner = p then
     2161        if GWonder[woZeus].EffectiveOwner = P then
    21622162        begin
    2163           GiveCivilReport(p, MoveInfo.Defender);
    2164           for i := 0 to nAdv - 1 do
    2165             if not(i in FutureTech) and (RW[p].Tech[i] < tsSeen) and
    2166               (RW[MoveInfo.Defender].Tech[i] >= tsApplicable) then
     2163          GiveCivilReport(P, MoveInfo.Defender);
     2164          for I := 0 to nAdv - 1 do
     2165            if not(I in FutureTech) and (RW[P].Tech[I] < tsSeen) and
     2166              (RW[MoveInfo.Defender].Tech[I] >= tsApplicable) then
    21672167            begin
    21682168              Happened := Happened or phStealTech;
     
    21722172        end;
    21732173        if Mode = moPlaying then
    2174           LogCheckBorders(p, nCity - 1, MoveInfo.Defender);
     2174          LogCheckBorders(P, nCity - 1, MoveInfo.Defender);
    21752175{$IFOPT O-} if Mode < moPlaying then
    2176           InvalidTreatyMap := not(1 shl p); {$ENDIF}
     2176          InvalidTreatyMap := not(1 shl P); {$ENDIF}
    21772177        // territory should not be considered for the rest of the command
    21782178        // execution, because during loading a game it's incorrect before
     
    21812181      else // city destroyed
    21822182      begin
    2183         DestroyCity_TellPlayers(MoveInfo.Defender, MoveInfo.Dcix, false);
     2183        DestroyCity_TellPlayers(MoveInfo.Defender, MoveInfo.Dcix, False);
    21842184        CheckBorders(ToLoc, MoveInfo.Defender);
    21852185      end;
    2186       RecalcPeaceMap(p);
     2186      RecalcPeaceMap(P);
    21872187      if Mode >= moMovie then
    2188         move(GWonder, Wonder, SizeOf(GWonder));
     2188        Move(GWonder, Wonder, SizeOf(GWonder));
    21892189    end; { if MoveInfo.MoveType=mtCapture }
    21902190
    21912191    if MoveInfo.MoveType = mtSpyMission then
    21922192    begin
    2193       MissionResult := DoSpyMission(p, MoveInfo.Defender, MoveInfo.Dcix,
     2193      MissionResult := DoSpyMission(P, MoveInfo.Defender, MoveInfo.Dcix,
    21942194        SpyMission);
    21952195      if (Mode = moPlaying) and (SpyMission = smStealForeignReports) then
    2196         CallPlayer(cShowMissionResult, p, MissionResult);
     2196        CallPlayer(cShowMissionResult, P, MissionResult);
    21972197    end;
    21982198
    21992199    Health := MoveInfo.EndHealth;
    2200     dec(Movement, MoveInfo.Cost);
     2200    Dec(Movement, MoveInfo.Cost);
    22012201    // transport unload
    22022202    if Master >= 0 then
    22032203    begin
    22042204      if PModel.Domain = dAir then
    2205         dec(Un[Master].AirLoad)
    2206       else
    2207       begin
    2208         dec(Un[Master].TroopLoad);
    2209         assert(Movement <= 0);
     2205        Dec(Un[Master].AirLoad)
     2206      else
     2207      begin
     2208        Dec(Un[Master].TroopLoad);
     2209        Assert(Movement <= 0);
    22102210      end;
    22112211      Master := -1;
     
    22132213
    22142214    if (Health <= 0) or (MoveInfo.MoveType = mtSpyMission) then
    2215       RemoveUnit(p, uix) // spy mission or victim of HostileDamage
     2215      RemoveUnit(P, uix) // spy mission or victim of HostileDamage
    22162216    else
    22172217    begin // transport load
     
    22202220      begin
    22212221        if PModel.Domain = dAir then
    2222           inc(Un[MoveInfo.ToMaster].AirLoad)
     2222          Inc(Un[MoveInfo.ToMaster].AirLoad)
    22232223        else
    2224           inc(Un[MoveInfo.ToMaster].TroopLoad);
     2224          Inc(Un[MoveInfo.ToMaster].TroopLoad);
    22252225      end
    22262226      else
    2227         PlaceUnit(p, uix);
     2227        PlaceUnit(P, uix);
    22282228    end;
    22292229
    22302230    if (MoveInfo.MoveType = mtCapture) and (nUpdateLoc > 0) then
    2231       RecalcMapZoC(p);
     2231      RecalcMapZoC(P);
    22322232    UpdateUnitMap(ToLoc, MoveInfo.MoveType = mtCapture);
    2233     for i := 0 to nUpdateLoc - 1 do
    2234       UpdateUnitMap(UpdateLoc[i]);
     2233    for I := 0 to nUpdateLoc - 1 do
     2234      UpdateUnitMap(UpdateLoc[I]);
    22352235    // tell about lost units of defender
    22362236
     
    22422242        (RealMap[ToLoc] and fTerImp = tiFort) or
    22432243        (RealMap[ToLoc] and fTerImp = tiBase) then
    2244         ExtDiscover := true;
     2244        ExtDiscover := True;
    22452245      if (PModel.Kind = mkDiplomat) or (PModel.Cap[mcSpy] > 0) then
    2246         i := lObserveSuper
     2246        I := lObserveSuper
    22472247      else if (PModel.Domain = dAir) or
    22482248        (PModel.Cap[mcRadar] + PModel.Cap[mcCarrier] > 0) then
    2249         i := lObserveAll
    2250       else
    2251         i := lObserveUnhidden;
     2249        I := lObserveAll
     2250      else
     2251        I := lObserveUnhidden;
    22522252      if ExtDiscover then
    22532253      begin
    2254         if Discover21(ToLoc, p, i, true, PModel.Domain = dGround) then
    2255           result := result or rEnemySpotted;
     2254        if Discover21(ToLoc, P, I, True, PModel.Domain = dGround) then
     2255          Result := Result or rEnemySpotted;
    22562256      end
    22572257      else
    22582258      begin
    2259         if Discover9(ToLoc, p, i, true, PModel.Domain = dGround) then
    2260           result := result or rEnemySpotted;
     2259        if Discover9(ToLoc, P, I, True, PModel.Domain = dGround) then
     2260          Result := Result or rEnemySpotted;
    22612261      end;
    22622262    end;
     
    22642264    if Mode >= moMovie then { show after-move in interface modules }
    22652265      for p1 := 0 to nPl - 1 do
    2266         if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or (bix[p1].Kind = btTerm))
     2266        if (1 shl p1 and GWatching <> 0) and ((p1 <> P) or (bix[p1].Kind = btTerm))
    22672267        then
    22682268        begin
     
    22732273          else
    22742274            MinLevel := lObserveUnhidden;
    2275           SeeFrom := (p1 = p) or (ObserveLevel[FromLoc] shr (2 * p1) and
     2275          SeeFrom := (p1 = P) or (ObserveLevel[FromLoc] shr (2 * p1) and
    22762276            3 >= MinLevel);
    2277           SeeTo := (p1 = p) or (ObserveLevel[ToLoc] shr (2 * p1) and
     2277          SeeTo := (p1 = P) or (ObserveLevel[ToLoc] shr (2 * p1) and
    22782278            3 >= MinLevel);
    22792279          if SeeTo and (MoveInfo.MoveType = mtCapture) then
     
    22832283          else if (MoveInfo.MoveType <> mtSpyMission) and SeeTo then
    22842284            CallPlayer(cShowUnitChanged, p1, ToLoc);
    2285           for i := 0 to nUpdateLoc - 1 do
    2286             if ObserveLevel[UpdateLoc[i]] shr (2 * p1) and 3 >= lObserveUnhidden
     2285          for I := 0 to nUpdateLoc - 1 do
     2286            if ObserveLevel[UpdateLoc[I]] shr (2 * p1) and 3 >= lObserveUnhidden
    22872287            then
    2288               CallPlayer(cShowUnitChanged, p1, UpdateLoc[i]);
     2288              CallPlayer(cShowUnitChanged, p1, UpdateLoc[I]);
    22892289        end;
    22902290  end;
    2291 end; // ExecuteMove
    2292 
    2293 function ExecuteAttack(p, uix, ToLoc: integer; var MoveInfo: TMoveInfo;
    2294   ShowMove: TShowMove): integer;
     2291end;
     2292
     2293function ExecuteAttack(P, uix, ToLoc: Integer; var MoveInfo: TMoveInfo;
     2294  ShowMove: TShowMove): Integer;
    22952295
    22962296  procedure WriteBattleHistory(ToLoc, FromLoc, Attacker, Defender, mixAttacker,
    2297     mixDefender: integer; AttackerLost, DefenderLost: boolean);
     2297    mixDefender: Integer; AttackerLost, DefenderLost: Boolean);
    22982298  var
    22992299    AttackerBattle, DefenderBattle: ^TBattle;
     
    23072307        ReallocMem(BattleHistory, nBattleHistory * (2 * SizeOf(TBattle)));
    23082308      AttackerBattle := @BattleHistory[nBattleHistory];
    2309       inc(nBattleHistory);
     2309      Inc(nBattleHistory);
    23102310    end;
    23112311    with RW[Defender] do
     
    23172317        ReallocMem(BattleHistory, nBattleHistory * (2 * SizeOf(TBattle)));
    23182318      DefenderBattle := @BattleHistory[nBattleHistory];
    2319       inc(nBattleHistory);
     2319      Inc(nBattleHistory);
    23202320    end;
    23212321    AttackerBattle.Enemy := Defender;
     
    23462346
    23472347var
    2348   i, p1, FromLoc, uix1, nUpdateLoc, ExpGain, ExpelToLoc, cix1: integer;
     2348  I, p1, FromLoc, uix1, nUpdateLoc, ExpGain, ExpelToLoc, cix1: Integer;
    23492349  PModel: ^TModel;
    2350   UpdateLoc: array [0 .. numax - 1] of integer;
    2351   LoseCityPop, CityDestroyed, SeeFrom, SeeTo, ZoCDefenderDestroyed: boolean;
     2350  UpdateLoc: array [0 .. numax - 1] of Integer;
     2351  LoseCityPop, CityDestroyed, SeeFrom, SeeTo, ZoCDefenderDestroyed: Boolean;
    23522352begin
    2353   result := 0;
    2354   with RW[p].Un[uix] do
     2353  Result := 0;
     2354  with RW[P].Un[uix] do
    23552355  begin
    2356     PModel := @RW[p].Model[mix];
     2356    PModel := @RW[P].Model[mix];
    23572357    FromLoc := Loc;
    23582358
     
    23602360    ShowMove.EndHealthDef := MoveInfo.EndHealthDef;
    23612361    if MoveInfo.MoveType = mtAttack then
    2362       WriteBattleHistory(ToLoc, FromLoc, p, MoveInfo.Defender, mix,
     2362      WriteBattleHistory(ToLoc, FromLoc, P, MoveInfo.Defender, mix,
    23632363        RW[MoveInfo.Defender].Un[MoveInfo.Duix].mix, MoveInfo.EndHealth <= 0,
    23642364        MoveInfo.EndHealthDef <= 0);
     
    23672367      begin
    23682368      if Mode>=moMovie then
    2369       CallPlayer(cShowCancelTreaty,MoveInfo.Defender,p);
    2370       CancelTreaty(p,MoveInfo.Defender)
     2369      CallPlayer(cShowCancelTreaty,MoveInfo.Defender,P);
     2370      CancelTreaty(P,MoveInfo.Defender)
    23712371      end; }
    23722372    if Mode >= moMovie then { show attack in interface modules }
    23732373      for p1 := 0 to nPl - 1 do
    2374         if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or (bix[p1].Kind = btTerm))
     2374        if (1 shl p1 and GWatching <> 0) and ((p1 <> P) or (bix[p1].Kind = btTerm))
    23752375        then
    23762376        begin
     
    23802380          if SeeFrom and SeeTo then
    23812381          begin
    2382             TellAboutModel(p1, p, mix);
    2383             if p1 = p then
     2382            TellAboutModel(p1, P, mix);
     2383            if p1 = P then
    23842384              ShowMove.emix := -1
    23852385            else
    2386               ShowMove.emix := emixSafe(p1, p, mix);
     2386              ShowMove.emix := emixSafe(p1, P, mix);
    23872387            CallPlayer(cShowAttacking, p1, ShowMove);
    23882388          end;
    23892389        end;
    23902390
    2391     LoseCityPop := false;
     2391    LoseCityPop := False;
    23922392    if (RealMap[ToLoc] and fCity <> 0) and
    23932393      ((MoveInfo.MoveType = mtAttack) and (MoveInfo.EndHealthDef <= 0) or
     
    24112411    if MoveInfo.MoveType = mtBombard then
    24122412    begin
    2413       assert(Movement >= 100);
     2413      Assert(Movement >= 100);
    24142414      if PModel.Attack = 0 then
    24152415        Flags := Flags and not unBombsLoaded;
    2416       dec(Movement, 100);
     2416      Dec(Movement, 100);
    24172417    end
    24182418    else if MoveInfo.MoveType = mtExpel then
    24192419    begin
    2420       assert(Movement >= 100);
     2420      Assert(Movement >= 100);
    24212421      Job := jNone;
    24222422      Flags := Flags and not unFortified;
    2423       dec(Movement, 100);
     2423      Dec(Movement, 100);
    24242424    end
    24252425    else
    24262426    begin
    2427       assert(MoveInfo.MoveType = mtAttack);
     2427      Assert(MoveInfo.MoveType = mtAttack);
    24282428      if MoveInfo.EndHealth = 0 then
    2429         RemoveUnit(p, uix, MoveInfo.Defender) // destroy attacker
     2429        RemoveUnit(P, uix, MoveInfo.Defender) // destroy attacker
    24302430      else
    24312431      begin // update attacker
     
    24342434          Exp := (nExp - 1) * ExpCost
    24352435        else
    2436           inc(Exp, ExpGain);
     2436          Inc(Exp, ExpGain);
    24372437        Health := MoveInfo.EndHealth;
    24382438        Job := jNone;
     
    24422442        Flags := Flags and not unFortified;
    24432443        if Movement > 100 then
    2444           dec(Movement, 100)
     2444          Dec(Movement, 100)
    24452445        else
    24462446          Movement := 0;
     
    24482448    end;
    24492449
    2450     ZoCDefenderDestroyed := false;
     2450    ZoCDefenderDestroyed := False;
    24512451    nUpdateLoc := 0;
    24522452    if MoveInfo.MoveType = mtExpel then
     
    24692469          PlaceUnit(MoveInfo.Defender, MoveInfo.Duix);
    24702470          UpdateLoc[nUpdateLoc] := Loc;
    2471           inc(nUpdateLoc);
     2471          Inc(nUpdateLoc);
    24722472          Flags := Flags or unWithdrawn;
    24732473        end;
     
    24802480          Exp := (nExp - 1) * ExpCost
    24812481        else
    2482           inc(Exp, ExpGain);
     2482          Inc(Exp, ExpGain);
    24832483        Health := MoveInfo.EndHealthDef;
    24842484      end
     
    24932493          (RealMap[ToLoc] and fTerImp <> tiFort)) or LoseCityPop and
    24942494          (RW[MoveInfo.Defender].City[MoveInfo.Dcix].Size = 2) then
    2495           RemoveAllUnits(MoveInfo.Defender, ToLoc, p)
     2495          RemoveAllUnits(MoveInfo.Defender, ToLoc, P)
    24962496          { no city, base or fortress }
    24972497        else
    2498           RemoveUnit(MoveInfo.Defender, MoveInfo.Duix, p);
     2498          RemoveUnit(MoveInfo.Defender, MoveInfo.Duix, P);
    24992499      end;
    25002500
     
    25092509              begin
    25102510                UpdateLoc[nUpdateLoc] := Loc;
    2511                 inc(nUpdateLoc);
     2511                Inc(nUpdateLoc);
    25122512              end;
    25132513          // unit will be removed -- remember position and update for all players
    2514           DestroyCity_TellPlayers(MoveInfo.Defender, MoveInfo.Dcix, false);
     2514          DestroyCity_TellPlayers(MoveInfo.Defender, MoveInfo.Dcix, False);
    25152515          CheckBorders(ToLoc, MoveInfo.Defender);
    2516           RecalcPeaceMap(p);
     2516          RecalcPeaceMap(P);
    25172517        end;
    25182518    end;
    25192519
    25202520    if CityDestroyed and (nUpdateLoc > 0) then
    2521       RecalcMapZoC(p)
     2521      RecalcMapZoC(P)
    25222522    else if ZoCDefenderDestroyed then
    2523       RecalcV8ZoC(p, ToLoc);
     2523      RecalcV8ZoC(P, ToLoc);
    25242524    UpdateUnitMap(FromLoc);
    25252525    UpdateUnitMap(ToLoc, LoseCityPop);
    2526     for i := 0 to nUpdateLoc - 1 do
    2527       UpdateUnitMap(UpdateLoc[i]);
     2526    for I := 0 to nUpdateLoc - 1 do
     2527      UpdateUnitMap(UpdateLoc[I]);
    25282528    // tell about lost units of defender
    25292529
    25302530    if Mode >= moMovie then
    25312531    begin
    2532       for i := 0 to RW[p].nEnemyModel - 1 do
    2533         with RW[p].EnemyModel[i] do
    2534           Lost := Destroyed[p, Owner, mix];
     2532      for I := 0 to RW[P].nEnemyModel - 1 do
     2533        with RW[P].EnemyModel[I] do
     2534          Lost := Destroyed[P, Owner, mix];
    25352535      for p1 := 0 to nPl - 1 do { show after-attack in interface modules }
    2536         if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or (bix[p1].Kind = btTerm))
     2536        if (1 shl p1 and GWatching <> 0) and ((p1 <> P) or (bix[p1].Kind = btTerm))
    25372537        then
    25382538        begin
     
    25592559    end;
    25602560  end;
    2561 end; // ExecuteAttack
    2562 
    2563 function MoveUnit(p, uix, dx, dy: integer; TestOnly: boolean): integer;
     2561end;
     2562
     2563function MoveUnit(P, uix, dx, dy: Integer; TestOnly: Boolean): Integer;
    25642564var
    2565   ToLoc: integer;
     2565  ToLoc: Integer;
    25662566  MoveInfo: TMoveInfo;
    25672567  ShowMove: TShowMove;
    25682568begin
    2569 {$IFOPT O-}assert(1 shl p and InvalidTreatyMap = 0); {$ENDIF}
    2570   with RW[p].Un[uix] do
     2569{$IFOPT O-}Assert(1 shl P and InvalidTreatyMap = 0); {$ENDIF}
     2570  with RW[P].Un[uix] do
    25712571  begin
    25722572    ToLoc := dLoc(Loc, dx, dy);
    25732573    if (ToLoc < 0) or (ToLoc >= MapSize) then
    25742574    begin
    2575       result := eInvalid;
    2576       exit;
     2575      Result := eInvalid;
     2576      Exit;
    25772577    end;
    2578     result := CalculateMove(p, uix, ToLoc, 3 - dy and 1, TestOnly, MoveInfo);
    2579     if result = eZOC_EnemySpotted then
     2578    Result := CalculateMove(P, uix, ToLoc, 3 - dy and 1, TestOnly, MoveInfo);
     2579    if Result = eZOC_EnemySpotted then
    25802580      ZOCTile := ToLoc;
    2581     if (result >= rExecuted) and not TestOnly then
     2581    if (Result >= rExecuted) and not TestOnly then
    25822582    begin
    25832583      ShowMove.dx := dx;
     
    25892589      ShowMove.Exp := Exp;
    25902590      ShowMove.Load := TroopLoad + AirLoad;
    2591       ShowMove.Owner := p;
     2591      ShowMove.Owner := P;
    25922592      if (TroopLoad > 0) or (AirLoad > 0) then
    25932593        ShowMove.Flags := unMulti
     
    26062606      case MoveInfo.MoveType of
    26072607        mtMove, mtCapture, mtSpyMission:
    2608           result := ExecuteMove(p, uix, ToLoc, MoveInfo, ShowMove) or result;
     2608          Result := ExecuteMove(P, uix, ToLoc, MoveInfo, ShowMove) or Result;
    26092609        mtAttack, mtBombard, mtExpel:
    2610           result := ExecuteAttack(p, uix, ToLoc, MoveInfo, ShowMove) or result;
     2610          Result := ExecuteAttack(P, uix, ToLoc, MoveInfo, ShowMove) or Result;
    26112611      end;
    26122612    end;
    2613   end; // with
    2614 end; { MoveUnit }
    2615 
    2616 function Server(Command, Player, Subject: integer; var Data): integer; stdcall;
    2617 
    2618   function CountPrice(const Offer: TOffer; PriceType: integer): integer;
     2613  end;
     2614end;
     2615
     2616function Server(Command, Player, Subject: Integer; var Data): Integer; stdcall;
     2617
     2618  function CountPrice(const Offer: TOffer; PriceType: Integer): Integer;
    26192619  var
    2620     i: integer;
     2620    I: Integer;
    26212621  begin
    2622     result := 0;
    2623     for i := 0 to Offer.nDeliver + Offer.nCost - 1 do
    2624       if Offer.Price[i] and $FFFF0000 = Cardinal(PriceType) then
    2625         inc(result);
     2622    Result := 0;
     2623    for I := 0 to Offer.nDeliver + Offer.nCost - 1 do
     2624      if Offer.Price[I] and $FFFF0000 = Cardinal(PriceType) then
     2625        Inc(Result);
    26262626  end;
    26272627
    26282628{ procedure UpdateBorderHelper;
    26292629  var
    2630   x, y, Loc, Loc1, dx, dy, ObserveMask: integer;
     2630  X, Y, Loc, Loc1, dx, dy, ObserveMask: Integer;
    26312631  begin
    26322632  ObserveMask:=3 shl (2*pTurn);
    2633   for x:=0 to lx-1 do for y:=0 to ly shr 1-1 do
     2633  for X:=0 to lx-1 do for Y:=0 to ly shr 1-1 do
    26342634  begin
    2635   Loc:=lx*(y*2)+x;
     2635  Loc:=lx*(Y*2)+X;
    26362636  if ObserveLevel[Loc] and ObserveMask<>0 then
    26372637  begin
    26382638  for dy:=0 to 1 do for dx:=0 to 1 do
    26392639  begin
    2640   Loc1:=(Loc+dx-1+lx) mod lx +lx*((y+dy)*2-1);
     2640  Loc1:=(Loc+dx-1+lx) mod lx +lx*((Y+dy)*2-1);
    26412641  if (Loc1>=0) and (Loc1<MapSize)
    26422642  and (ObserveLevel[Loc1] and ObserveMask<>0) then
     
    26662666  ptInvalid = 8;
    26672667
    2668   function ProjectType(Project: integer): integer;
     2668  function ProjectType(Project: Integer): Integer;
    26692669  begin
    26702670    if Project and cpCompleted <> 0 then
    2671       result := ptSelect
     2671      Result := ptSelect
    26722672    else if Project and (cpImp + cpIndex) = cpImp + imTrGoods then
    2673       result := ptTrGoods
     2673      Result := ptTrGoods
    26742674    else if Project and cpImp = 0 then
    26752675      if RW[Player].Model[Project and cpIndex].Kind = mkCaravan then
    2676         result := ptCaravan
    2677       else
    2678         result := ptUn
     2676        Result := ptCaravan
     2677      else
     2678        Result := ptUn
    26792679    else if Project and cpIndex >= nImp then
    2680       result := ptInvalid
     2680      Result := ptInvalid
    26812681    else if Imp[Project and cpIndex].Kind = ikWonder then
    2682       result := ptWonder
     2682      Result := ptWonder
    26832683    else if Imp[Project and cpIndex].Kind = ikShipPart then
    2684       result := ptShip
     2684      Result := ptShip
    26852685    else
    2686       result := ptImp;
     2686      Result := ptImp;
    26872687  end;
    26882688
    26892689var
    2690   d, i, j, p1, p2, pt0, pt1, uix1, cix1, Loc0, Loc1, dx, dy, NewCap, MinCap,
     2690  D, I, J, p1, p2, pt0, pt1, uix1, cix1, Loc0, Loc1, dx, dy, NewCap, MinCap,
    26912691    MaxCap, CapWeight, Cost, NextProd, Preq, TotalFood, TotalProd, CheckSum,
    26922692    StopTurn, FutureMCost, NewProject, OldImp, mix, V8, V21, AStr, DStr,
    2693     ABaseDamage, DBaseDamage: integer;
     2693    ABaseDamage, DBaseDamage: Integer;
    26942694  CityReport: TCityReport;
    26952695  FormerCLState: TCmdListState;
     
    26982698  ShowShipChange: TShowShipChange;
    26992699  ShowNegoData: TShowNegoData;
    2700   logged, ok, HasShipChanged, AllHumansDead, OfferFullySupported: boolean;
    2701 
    2702 begin { >>>server }
     2700  logged, ok, HasShipChanged, AllHumansDead, OfferFullySupported: Boolean;
     2701begin
    27032702  if Command = sTurn then
    27042703  begin
     
    27092708  end;
    27102709
    2711   assert(MapSize = lx * ly);
    2712   assert(Command and (sctMask or sExecute) <> sctInternal or sExecute);
     2710  Assert(MapSize = lx * ly);
     2711  Assert(Command and (sctMask or sExecute) <> sctInternal or sExecute);
    27132712  // not for internal commands
    27142713  if (Command < 0) or (Command >= $10000) then
    27152714  begin
    2716     result := eUnknown;
    2717     exit;
     2715    Result := eUnknown;
     2716    Exit;
    27182717  end;
    27192718
     
    27222721    ((Subject < 0) or (Subject >= $1000))) then
    27232722  begin
    2724     result := eInvalid;
    2725     exit;
     2723    Result := eInvalid;
     2724    Exit;
    27262725  end;
    27272726
     
    27322731  begin
    27332732    PutMessage(1 shl 16 + 1, Format('NOT Alive: %d', [Player]));
    2734     result := eNoTurn;
    2735     exit;
     2733    Result := eNoTurn;
     2734    Exit;
    27362735  end;
    27372736
    2738   result := eOK;
     2737  Result := eOK;
    27392738
    27402739  // check if command allowed now
     
    27592758    PutMessage(1 shl 16 + 1, Format('No Turn: %d calls %x',
    27602759      [Player, Command shr 4]));
    2761     result := eNoTurn;
    2762     exit;
     2760    Result := eNoTurn;
     2761    Exit;
    27632762  end;
    27642763
     
    27682767  HandoverStack[nHandoverStack] := Player + $1000;
    27692768  HandoverStack[nHandoverStack + 1] := Command;
    2770   inc(nHandoverStack, 2);
     2769  Inc(nHandoverStack, 2);
    27712770
    27722771  InvalidTreatyMap := 0;
     
    27812780    FormerCLState := CL.State;
    27822781    CL.Put(Command, Player, Subject, @Data);
    2783     logged := true;
     2782    logged := True;
    27842783  end
    27852784  else
    2786     logged := false;
     2785    logged := False;
    27872786
    27882787  case Command of
     
    27992798
    28002799    sGetDebugMap:
    2801       pointer(Data) := DebugMap[Subject];
     2800      Pointer(Data) := DebugMap[Subject];
    28022801
    28032802    { sChangeSuperView:
    28042803      if Difficulty[Player]=0 then
    28052804      begin
    2806       for i:=0 to nBrain-1 do if Brain[i].Initialized then
    2807       CallClient(i, cShowSuperView, Subject)
     2805      for I:=0 to nBrain-1 do if Brain[I].Initialized then
     2806      CallClient(I, cShowSuperView, Subject)
    28082807      end
    2809       else result:=eInvalid; }
     2808      else Result:=eInvalid; }
    28102809
    28112810    sRefreshDebugMap:
     
    28302829          else
    28312830            StopTurn := RW[Player].EnemyReport[Subject].TurnOfCivilReport + 1;
    2832         move(Stat[Command shr 4 and $F, Subject]^, Data,
    2833           StopTurn * SizeOf(integer));
     2831        Move(Stat[Command shr 4 and $F, Subject]^, Data,
     2832          StopTurn * SizeOf(Integer));
    28342833        FillChar(TChart(Data)[StopTurn], (GTurn - StopTurn) *
    2835           SizeOf(integer), 0);
     2834          SizeOf(Integer), 0);
    28362835      end
    28372836      else
    2838         result := eInvalid;
     2837        Result := eInvalid;
    28392838
    28402839    sGetTechCost:
    2841       integer(Data) := TechCost(Player);
     2840      Integer(Data) := TechCost(Player);
    28422841
    28432842    sGetAIInfo:
    28442843      if AIInfo[Subject] = '' then
    2845         pchar(Data) := nil
    2846       else
    2847         pchar(Data) := @AIInfo[Subject][1];
     2844        PChar(Data) := nil
     2845      else
     2846        PChar(Data) := @AIInfo[Subject][1];
    28482847
    28492848    sGetAICredits:
    28502849      if AICredits = '' then
    2851         pchar(Data) := nil
    2852       else
    2853         pchar(Data) := @AICredits[1];
     2850        PChar(Data) := nil
     2851      else
     2852        PChar(Data) := @AICredits[1];
    28542853
    28552854    sGetVersion:
    2856       integer(Data) := CevoVersion;
     2855      Integer(Data) := CevoVersion;
    28572856
    28582857    sGetGameChanged:
    28592858      if Player <> 0 then
    2860         result := eInvalid
     2859        Result := eInvalid
    28612860      else if (CL <> nil) and (CL.State.nLog = nLogOpened) and
    28622861        (CL.State.MoveCode = 0) and not HasCityTileChanges and
    28632862        not HasChanges(Player) then
    2864         result := eNotChanged;
     2863        Result := eNotChanged;
    28652864
    28662865    sGetTileInfo:
    28672866      if (Subject >= 0) and (Subject < MapSize) then
    2868         result := GetTileInfo(Player, -2, Subject, TTileInfo(Data))
    2869       else
    2870         result := eInvalid;
     2867        Result := GetTileInfo(Player, -2, Subject, TTileInfo(Data))
     2868      else
     2869        Result := eInvalid;
    28712870
    28722871    sGetCityTileInfo:
    28732872      if (Subject >= 0) and (Subject < MapSize) then
    2874         result := GetTileInfo(Player, -1, Subject, TTileInfo(Data))
    2875       else
    2876         result := eInvalid;
     2873        Result := GetTileInfo(Player, -1, Subject, TTileInfo(Data))
     2874      else
     2875        Result := eInvalid;
    28772876
    28782877    sGetHypoCityTileInfo:
     
    28812880        if (TTileInfo(Data).ExplCity < 0) or
    28822881          (TTileInfo(Data).ExplCity >= RW[Player].nCity) then
    2883           result := eInvalid
     2882          Result := eInvalid
    28842883        else if ObserveLevel[Subject] shr (Player * 2) and 3 = 0 then
    2885           result := eNoPreq
     2884          Result := eNoPreq
    28862885        else
    2887           result := GetTileInfo(Player, TTileInfo(Data).ExplCity, Subject,
     2886          Result := GetTileInfo(Player, TTileInfo(Data).ExplCity, Subject,
    28882887            TTileInfo(Data));
    28892888      end
    28902889      else
    2891         result := eInvalid;
     2890        Result := eInvalid;
    28922891
    28932892    sGetJobProgress:
     
    28952894      begin
    28962895        if ObserveLevel[Subject] shr (Player * 2) and 3 = 0 then
    2897           result := eNoPreq
     2896          Result := eNoPreq
    28982897        else
    2899           result := GetJobProgress(Player, Subject, TJobProgressData(Data));
     2898          Result := GetJobProgress(Player, Subject, TJobProgressData(Data));
    29002899      end
    29012900      else
    2902         result := eInvalid;
     2901        Result := eInvalid;
    29032902
    29042903    sGetModels:
     
    29122911      end
    29132912      else
    2914         result := eInvalid;
     2913        Result := eInvalid;
    29152914
    29162915    sGetUnits:
    29172916      if (Subject >= 0) and (Subject < MapSize) and
    29182917        (ObserveLevel[Subject] shr (Player * 2) and 3 = lObserveSuper) then
    2919         integer(Data) := GetUnitStack(Player, Subject)
    2920       else
    2921         result := eNoPreq;
     2918        Integer(Data) := GetUnitStack(Player, Subject)
     2919      else
     2920        Result := eNoPreq;
    29222921
    29232922    sGetDefender:
    29242923      if (Subject >= 0) and (Subject < MapSize) and (Occupant[Subject] = Player)
    29252924      then
    2926         Strongest(Subject, integer(Data), d, i, j)
    2927       else
    2928         result := eInvalid;
     2925        Strongest(Subject, Integer(Data), D, I, J)
     2926      else
     2927        Result := eInvalid;
    29292928
    29302929    sGetBattleForecast, sGetBattleForecastEx:
     
    29362935            ((pAtt = Player) or (RWemix[Player, pAtt, mixAtt] >= 0)) then
    29372936          begin
    2938             result := GetBattleForecast(Subject, TBattleForecast(Data), uix1,
     2937            Result := GetBattleForecast(Subject, TBattleForecast(Data), uix1,
    29392938              cix1, AStr, DStr, ABaseDamage, DBaseDamage);
    29402939            if Command = sGetBattleForecastEx then
     
    29452944              TBattleForecastEx(Data).DBaseDamage := DBaseDamage;
    29462945            end;
    2947             if result = eOK then
    2948               result := eInvalid; // no enemy unit there!
     2946            if Result = eOK then
     2947              Result := eInvalid; // no enemy unit there!
    29492948          end
    29502949          else
    2951             result := eInvalid
    2952       else
    2953         result := eInvalid;
     2950            Result := eInvalid
     2951      else
     2952        Result := eInvalid;
    29542953
    29552954    sGetUnitReport:
    29562955      if (Subject < 0) or (Subject >= RW[Player].nUn) or
    29572956        (RW[Player].Un[Subject].Loc < 0) then
    2958         result := eInvalid
     2957        Result := eInvalid
    29592958      else
    29602959        GetUnitReport(Player, Subject, TUnitReport(Data));
     
    29632962      if (Subject < 0) or (Subject >= RW[Player].nUn) or
    29642963        (RW[Player].Un[Subject].Loc < 0) then
    2965         result := eInvalid
    2966       else
    2967         result := GetMoveAdvice(Player, Subject, TMoveAdviceData(Data));
     2964        Result := eInvalid
     2965      else
     2966        Result := GetMoveAdvice(Player, Subject, TMoveAdviceData(Data));
    29682967
    29692968    sGetPlaneReturn:
     
    29712970        (RW[Player].Un[Subject].Loc < 0) or
    29722971        (RW[Player].Model[RW[Player].Un[Subject].mix].Domain <> dAir) then
    2973         result := eInvalid
     2972        Result := eInvalid
    29742973      else
    29752974      begin
    29762975        if CanPlaneReturn(Player, Subject, TPlaneReturnData(Data)) then
    2977           result := eOK
     2976          Result := eOK
    29782977        else
    2979           result := eNoWay;
     2978          Result := eNoWay;
    29802979      end;
    29812980
     
    29882987          Owner := Player;
    29892988          SearchCity(Subject, Owner, cix1);
    2990           c := RW[Owner].City[cix1];
    2991           if (Owner <> Player) and (c.Project and cpImp = 0) then
    2992             TellAboutModel(Player, Owner, c.Project and cpIndex);
     2989          C := RW[Owner].City[cix1];
     2990          if (Owner <> Player) and (C.Project and cpImp = 0) then
     2991            TellAboutModel(Player, Owner, C.Project and cpIndex);
    29932992        end
    29942993      else
    2995         result := eInvalid;
     2994        Result := eInvalid;
    29962995
    29972996    sGetCityReport:
    29982997      if (Subject < 0) or (Subject >= RW[Player].nCity) or
    29992998        (RW[Player].City[Subject].Loc < 0) then
    3000         result := eInvalid
    3001       else
    3002         result := GetCityReport(Player, Subject, TCityReport(Data));
     2999        Result := eInvalid
     3000      else
     3001        Result := GetCityReport(Player, Subject, TCityReport(Data));
    30033002
    30043003    sGetCityReportNew:
    30053004      if (Subject < 0) or (Subject >= RW[Player].nCity) or
    30063005        (RW[Player].City[Subject].Loc < 0) then
    3007         result := eInvalid
     3006        Result := eInvalid
    30083007      else
    30093008        GetCityReportNew(Player, Subject, TCityReportNew(Data));
     
    30123011      if (Subject < 0) or (Subject >= RW[Player].nCity) or
    30133012        (RW[Player].City[Subject].Loc < 0) then
    3014         result := eInvalid
     3013        Result := eInvalid
    30153014      else
    30163015        GetCityAreaInfo(Player, RW[Player].City[Subject].Loc,
     
    30323031      end
    30333032      else
    3034         result := eInvalid;
     3033        Result := eInvalid;
    30353034
    30363035    sGetEnemyCityReportNew:
     
    30493048      end
    30503049      else
    3051         result := eInvalid;
     3050        Result := eInvalid;
    30523051
    30533052    sGetEnemyCityAreaInfo:
     
    30633062      end
    30643063      else
    3065         result := eInvalid;
     3064        Result := eInvalid;
    30663065
    30673066    sGetCityTileAdvice:
    30683067      if (Subject < 0) or (Subject >= RW[Player].nCity) or
    30693068        (RW[Player].City[Subject].Loc < 0) then
    3070         result := eInvalid
     3069        Result := eInvalid
    30713070      else
    30723071        GetCityTileAdvice(Player, Subject, TCityTileAdviceData(Data));
     
    30813080          EditTile(Loc, NewTile)
    30823081      else
    3083         result := eInvalid;
     3082        Result := eInvalid;
    30843083
    30853084    sRandomMap:
     
    30873086      begin
    30883087        CreateElevation;
    3089         PreviewElevation := false;
    3090         CreateMap(false);
     3088        PreviewElevation := False;
     3089        CreateMap(False);
    30913090        FillChar(ObserveLevel, MapSize * 4, 0);
    30923091        DiscoverAll(Player, lObserveSuper);
    30933092      end
    30943093      else
    3095         result := eInvalid;
     3094        Result := eInvalid;
    30963095
    30973096    sMapGeneratorRequest:
    30983097      if not MapGeneratorAvailable then
    3099         result := eInvalid;
     3098        Result := eInvalid;
    31003099
    31013100    {
     
    31053104    sTurn, sTurn - sExecute:
    31063105      begin
    3107         AllHumansDead := true;
     3106        AllHumansDead := True;
    31083107        for p1 := 0 to nPl - 1 do
    31093108          if (1 shl p1 and GAlive <> 0) and (bix[p1].Kind = btTerm) then
    3110             AllHumansDead := false;
     3109            AllHumansDead := False;
    31113110        if (pDipActive >= 0) // still in negotiation mode
    31123111          or (pTurn = 0) and ((GWinner > 0) or (GTurn = MaxTurn) or
    31133112          (Difficulty[0] > 0) and AllHumansDead) then // game end reached
    3114           result := eViolation
     3113          Result := eViolation
    31153114        else if Command >= sExecute then
    31163115        begin
     
    31233122            begin
    31243123              LogChanges;
    3125               SaveGame('~' + LogFileName, true);
     3124              SaveGame('~' + LogFileName, True);
    31263125            end;
    31273126{$ENDIF}
     
    31383137            TotalFood := 0;
    31393138            TotalProd := 0;
    3140             for i := 0 to RW[pTurn].nCity - 1 do
    3141               if RW[pTurn].City[i].Loc >= 0 then
     3139            for I := 0 to RW[pTurn].nCity - 1 do
     3140              if RW[pTurn].City[I].Loc >= 0 then
    31423141              begin
    3143                 inc(TotalFood, RW[pTurn].City[i].Food);
    3144                 inc(TotalProd, RW[pTurn].City[i].Prod);
     3142                Inc(TotalFood, RW[pTurn].City[I].Food);
     3143                Inc(TotalProd, RW[pTurn].City[I].Prod);
    31453144              end;
    31463145            CheckSum := TotalFood and 7 + TotalProd and 7 shl 3 +
     
    31533152          begin
    31543153            if CheckSum <> Subject then
    3155               LoadOK := false;
     3154              LoadOK := False;
    31563155          end
    31573156          else // save checksum
     
    31803179            pTurn := (pTurn + 1) mod nPl;
    31813180            if pTurn = 0 then
    3182               inc(GTurn);
     3181              Inc(GTurn);
    31833182            if Assigned(bix[pTurn]) and ((1 shl pTurn) and GAlive = 0) then
    31843183            begin // already made extinct -- continue statistics
     
    32193218    sBreak, sResign, sNextRound, sReload:
    32203219      if Mode = moMovie then
    3221         MovieStopped := true
     3220        MovieStopped := True
    32223221      else
    32233222      begin
     
    32253224        begin
    32263225          ok := (Difficulty[0] = 0) and (bix[0].Kind <> btNoTerm) and
    3227             (integer(Data) >= 0) and (integer(Data) < GTurn);
     3226            (Integer(Data) >= 0) and (Integer(Data) < GTurn);
    32283227          for p1 := 1 to nPl - 1 do
    32293228            if bix[p1].Kind = btTerm then
    3230               ok := false;
     3229              ok := False;
    32313230          // allow reload in AI-only games only
    32323231        end
     
    32373236          if (Command = sBreak) or (Command = sResign) then
    32383237            Notify(ntBackOn);
    3239           for i := 0 to Brains.Count - 1 do
    3240             if Brains[i].Initialized then
     3238          for I := 0 to Brains.Count - 1 do
     3239            if Brains[I].Initialized then
    32413240            begin
    3242               if Brains[i].Kind = btAI then
    3243                 Notify(ntDeinitModule, i);
    3244               CallClient(i, cBreakGame, nil^);
     3241              if Brains[I].Kind = btAI then
     3242                Notify(ntDeinitModule, I);
     3243              CallClient(I, cBreakGame, nil^);
    32453244            end;
    32463245          Notify(ntEndInfo);
     
    32493248            LogCityTileChanges;
    32503249            LogChanges;
    3251             SaveGame(LogFileName, false);
     3250            SaveGame(LogFileName, False);
    32523251          end;
    32533252          DeleteFile(SavePath + '~' + LogFileName);
     
    32623261                LandMass, MaxTurn);
    32633262            sReload:
    3264               LoadGame(SavePath, LogFileName, integer(Data), false);
     3263              LoadGame(SavePath, LogFileName, Integer(Data), False);
    32653264          end;
    32663265        end
    32673266        else
    3268           result := eInvalid;
     3267          Result := eInvalid;
    32693268      end;
    32703269
     
    32833282      end
    32843283      else
    3285         result := eInvalid;
     3284        Result := eInvalid;
    32863285
    32873286    scContact .. scContact + (nPl - 1) shl 4, scContact - sExecute .. scContact
    32883287      - sExecute + (nPl - 1) shl 4:
    32893288      if (pDipActive >= 0) or (1 shl (Command shr 4 and $F) and GAlive = 0) then
    3290         result := eInvalid
     3289        Result := eInvalid
    32913290      else if GWinner > 0 then
    3292         result := eViolation // game end reached
     3291        Result := eViolation // game end reached
    32933292      else if RW[Player].Treaty[Command shr 4 and $F] = trNoContact then
    3294         result := eNoPreq
     3293        Result := eNoPreq
    32953294      else if GTurn < GColdWarStart + ColdWarTurns then
    3296         result := eColdWar
     3295        Result := eColdWar
    32973296      else if RW[Player].Government = gAnarchy then
    3298         result := eAnarchy
     3297        Result := eAnarchy
    32993298      else if RW[Command shr 4 and $F].Government = gAnarchy then
    33003299      begin
    3301         result := eAnarchy;
     3300        Result := eAnarchy;
    33023301        LastEndClientCommand := scReject; // enable cancel treaty
    33033302        pContacted := Command shr 4 and $F;
     
    33073306        pContacted := Command shr 4 and $F;
    33083307        pDipActive := pContacted;
    3309         assert(Mode = moPlaying);
     3308        Assert(Mode = moPlaying);
    33103309        Inform(pDipActive);
    33113310        ChangeClientWhenDone(scContact, pDipActive, pTurn, 4);
     
    33183317        begin // contact requested and not accepted yet
    33193318          pDipActive := -1;
    3320           assert(Mode = moPlaying);
     3319          Assert(Mode = moPlaying);
    33213320          ChangeClientWhenDone(cContinue, pTurn, nil^, 0);
    33223321        end;
    33233322      end
    33243323      else
    3325         result := eInvalid;
     3324        Result := eInvalid;
    33263325
    33273326    scDipStart, scDipStart - sExecute:
     
    33343333            RW[pTurn].Credibility;
    33353334          pDipActive := pTurn;
    3336           assert(Mode = moPlaying);
     3335          Assert(Mode = moPlaying);
    33373336          IntServer(sIntHaveContact, pTurn, pContacted, nil^);
    33383337          ChangeClientWhenDone(scDipStart, pDipActive, nil^, 0);
     
    33403339      end
    33413340      else
    3342         result := eInvalid;
     3341        Result := eInvalid;
    33433342
    33443343    scDipNotice, scDipAccept, scDipCancelTreaty, scDipBreak,
     
    33473346      if pDipActive >= 0 then
    33483347      begin
    3349         assert(Mode = moPlaying);
     3348        Assert(Mode = moPlaying);
    33503349        if pDipActive = pTurn then
    33513350          p1 := pContacted
     
    33633362            // check if offer can be accepted
    33643363            if nDeliver + nCost = 0 then
    3365               result := eOfferNotAcceptable;
    3366             for i := 0 to nDeliver + nCost - 1 do
    3367               if Price[i] = opChoose then
    3368                 result := eOfferNotAcceptable;
    3369             for i := 0 to nCost - 1 do
    3370               if not PayPrice(pDipActive, p1, Price[nDeliver + i], false) then
    3371                 result := eOfferNotAcceptable;
    3372             if (Command >= sExecute) and (result >= rExecuted) then
     3364              Result := eOfferNotAcceptable;
     3365            for I := 0 to nDeliver + nCost - 1 do
     3366              if Price[I] = opChoose then
     3367                Result := eOfferNotAcceptable;
     3368            for I := 0 to nCost - 1 do
     3369              if not PayPrice(pDipActive, p1, Price[nDeliver + I], False) then
     3370                Result := eOfferNotAcceptable;
     3371            if (Command >= sExecute) and (Result >= rExecuted) then
    33733372            begin
    33743373              IntServer(sIntPayPrices + nDeliver + nCost, p1, pDipActive,
     
    33773376
    33783377              // tell other players about ship part trades
    3379               HasShipChanged := false;
     3378              HasShipChanged := False;
    33803379              FillChar(ShowShipChange, SizeOf(ShowShipChange), 0);
    3381               for i := 0 to nDeliver + nCost - 1 do
    3382                 if Price[i] and opMask = opShipParts then
     3380              for I := 0 to nDeliver + nCost - 1 do
     3381                if Price[I] and opMask = opShipParts then
    33833382                begin
    3384                   HasShipChanged := true;
    3385                   if i >= nDeliver then
     3383                  HasShipChanged := True;
     3384                  if I >= nDeliver then
    33863385                  begin // p1 has demanded from pDipActive
    3387                     ShowShipChange.Ship1Change[Price[i] shr 16 and 3] :=
    3388                       +integer(Price[i] and $FFFF);
    3389                     ShowShipChange.Ship2Change[Price[i] shr 16 and 3] :=
    3390                       -integer(Price[i] and $FFFF);
     3386                    ShowShipChange.Ship1Change[Price[I] shr 16 and 3] :=
     3387                      +Integer(Price[I] and $FFFF);
     3388                    ShowShipChange.Ship2Change[Price[I] shr 16 and 3] :=
     3389                      -Integer(Price[I] and $FFFF);
    33913390                  end
    33923391                  else
    33933392                  begin // p1 has delivered to pDipActive
    3394                     ShowShipChange.Ship1Change[Price[i] shr 16 and 3] :=
    3395                       -integer(Price[i] and $FFFF);
    3396                     ShowShipChange.Ship2Change[Price[i] shr 16 and 3] :=
    3397                       +integer(Price[i] and $FFFF);
     3393                    ShowShipChange.Ship1Change[Price[I] shr 16 and 3] :=
     3394                      -Integer(Price[I] and $FFFF);
     3395                    ShowShipChange.Ship2Change[Price[I] shr 16 and 3] :=
     3396                      +Integer(Price[I] and $FFFF);
    33983397                  end;
    33993398                end;
     
    34073406                    (1 shl p2 and (GAlive or GWatching) <> 0) then
    34083407                  begin
    3409                     move(GShip, RW[p2].Ship, SizeOf(GShip));
     3408                    Move(GShip, RW[p2].Ship, SizeOf(GShip));
    34103409                    if 1 shl p2 and GWatching <> 0 then
    34113410                      CallPlayer(cShowShipChange, p2, ShowShipChange);
     
    34203419            (GTurn < RW[pDipActive].LastCancelTreaty[p1] + CancelTreatyTurns)
    34213420          then
    3422             result := eCancelTreatyRush
     3421            Result := eCancelTreatyRush
    34233422          else if Command >= sExecute then
    34243423          begin
     
    34273426              if (p2 <> p1) and (1 shl p2 and PeaceEnded <> 0) then
    34283427              begin
    3429                 i := p1 shl 4 + pDipActive;
    3430                 CallPlayer(cShowSupportAllianceAgainst, p2, i);
     3428                I := p1 shl 4 + pDipActive;
     3429                CallPlayer(cShowSupportAllianceAgainst, p2, I);
    34313430              end;
    34323431            for p2 := 0 to nPl - 1 do
    34333432              if (p2 <> p1) and (1 shl p2 and PeaceEnded <> 0) then
    34343433              begin
    3435                 i := p2;
    3436                 CallPlayer(cShowCancelTreatyByAlliance, pDipActive, i);
     3434                I := p2;
     3435                CallPlayer(cShowCancelTreatyByAlliance, pDipActive, I);
    34373436              end;
    34383437          end;
    34393438        end
    34403439        else
    3441           result := eInvalid;
    3442         if (Command >= sExecute) and (result >= rExecuted) then
     3440          Result := eInvalid;
     3441        if (Command >= sExecute) and (Result >= rExecuted) then
    34433442          if LastEndClientCommand = scDipBreak then
    34443443          begin // break negotiation
     
    34623461      end
    34633462      else
    3464         result := eInvalid;
     3463        Result := eInvalid;
    34653464
    34663465    scDipOffer, scDipOffer - sExecute:
     
    34753474            pDipActive := -1;
    34763475            CallPlayer(cShowEndContact, pContacted, nil^);
    3477             assert(Mode = moPlaying);
     3476            Assert(Mode = moPlaying);
    34783477            ChangeClientWhenDone(cContinue, pTurn, nil^, 0);
    34793478          end;
     
    34883487          if RW[pDipActive].Treaty[p1] < trPeace then
    34893488          begin // no tribute allowed!
    3490             for i := 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do
    3491               if (TOffer(Data).Price[i] and opMask = opTribute) then
    3492                 result := eInvalidOffer;
    3493             for i := 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do
    3494               if (TOffer(Data).Price[i] = opTreaty + trPeace) then
    3495                 result := eOK;
     3489            for I := 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do
     3490              if (TOffer(Data).Price[I] and opMask = opTribute) then
     3491                Result := eInvalidOffer;
     3492            for I := 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do
     3493              if (TOffer(Data).Price[I] = opTreaty + trPeace) then
     3494                Result := eOK;
    34963495          end;
    3497           for i := 0 to TOffer(Data).nDeliver - 1 do
    3498             if (TOffer(Data).Price[i] <> opChoose) and
    3499               not PayPrice(pDipActive, p1, TOffer(Data).Price[i], false) then
    3500               result := eInvalidOffer;
     3496          for I := 0 to TOffer(Data).nDeliver - 1 do
     3497            if (TOffer(Data).Price[I] <> opChoose) and
     3498              not PayPrice(pDipActive, p1, TOffer(Data).Price[I], False) then
     3499              Result := eInvalidOffer;
    35013500          if CountPrice(TOffer(Data), opTreaty) > 1 then
    3502             result := eInvalidOffer;
    3503           for i := 0 to nShipPart - 1 do
    3504             if CountPrice(TOffer(Data), opShipParts + i shl 16) > 1 then
    3505               result := eInvalidOffer;
     3501            Result := eInvalidOffer;
     3502          for I := 0 to nShipPart - 1 do
     3503            if CountPrice(TOffer(Data), opShipParts + I shl 16) > 1 then
     3504              Result := eInvalidOffer;
    35063505          if CountPrice(TOffer(Data), opMoney) > 1 then
    3507             result := eInvalidOffer;
     3506            Result := eInvalidOffer;
    35083507          if CountPrice(TOffer(Data), opTribute) > 1 then
    3509             result := eInvalidOffer;
     3508            Result := eInvalidOffer;
    35103509          case CountPrice(TOffer(Data), opChoose) of
    35113510            0:
     
    35133512            1:
    35143513              if (TOffer(Data).nCost = 0) or (TOffer(Data).nDeliver = 0) then
    3515                 result := eInvalidOffer;
     3514                Result := eInvalidOffer;
    35163515          else
    3517             result := eInvalidOffer;
     3516            Result := eInvalidOffer;
    35183517          end;
    35193518
    35203519          // !!! check here if cost can be demanded
    35213520
    3522           if (Command >= sExecute) and (result >= rExecuted) then
     3521          if (Command >= sExecute) and (Result >= rExecuted) then
    35233522          begin
    35243523            OfferFullySupported := (TOffer(Data).nDeliver <= 2) and
    35253524              (TOffer(Data).nCost <= 2); // >2 no more allowed
    3526             for i := 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do
     3525            for I := 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do
    35273526            begin
    3528               if TOffer(Data).Price[i] and opMask = opTribute then
    3529                 OfferFullySupported := false;
     3527              if TOffer(Data).Price[I] and opMask = opTribute then
     3528                OfferFullySupported := False;
    35303529              // tribute no more part of the game
    3531               if (TOffer(Data).Price[i] and opMask = opTreaty) and
    3532                 (TOffer(Data).Price[i] - opTreaty <= RW[pDipActive].Treaty[p1])
     3530              if (TOffer(Data).Price[I] and opMask = opTreaty) and
     3531                (TOffer(Data).Price[I] - opTreaty <= RW[pDipActive].Treaty[p1])
    35333532              then
    3534                 OfferFullySupported := false;
     3533                OfferFullySupported := False;
    35353534              // agreed treaty end no more part of the game
    3536               if TOffer(Data).Price[i] = opTreaty + trCeaseFire then
    3537                 OfferFullySupported := false;
     3535              if TOffer(Data).Price[I] = opTreaty + trCeaseFire then
     3536                OfferFullySupported := False;
    35383537              // ceasefire no more part of the game
    35393538            end;
     
    35603559              LastOffer := TOffer(Data);
    35613560              // show offered things to receiver
    3562               for i := 0 to LastOffer.nDeliver - 1 do
    3563                 ShowPrice(pDipActive, p1, LastOffer.Price[i]);
     3561              for I := 0 to LastOffer.nDeliver - 1 do
     3562                ShowPrice(pDipActive, p1, LastOffer.Price[I]);
    35643563              pDipActive := p1;
    3565               assert(Mode = moPlaying);
     3564              Assert(Mode = moPlaying);
    35663565              ChangeClientWhenDone(scDipOffer, pDipActive, LastOffer,
    35673566                SizeOf(LastOffer));
    3568             end
    3569           end
     3567            end;
     3568          end;
    35703569        end
    35713570      else
    3572         result := eInvalid;
     3571        Result := eInvalid;
    35733572
    35743573    {
     
    35833582      end
    35843583      else
    3585         result := eInvalid;
     3584        Result := eInvalid;
    35863585
    35873586    sSetTestFlag:
     
    35933592      end
    35943593      else
    3595         result := eInvalid;
     3594        Result := eInvalid;
    35963595
    35973596    sSetGovernment, sSetGovernment - sExecute:
     
    35993598{$IFDEF TEXTLOG}CmdInfo := Format('SetGovernment P%d: %d', [Player, Subject]); {$ENDIF}
    36003599        if RW[Player].Happened and phChangeGov = 0 then
    3601           result := eViolation
     3600          Result := eViolation
    36023601        else if RW[Player].Government = Subject then
    3603           result := eNotChanged
     3602          Result := eNotChanged
    36043603        else if (Subject >= nGov) then
    3605           result := eInvalid
     3604          Result := eInvalid
    36063605        else if (Subject >= gMonarchy) and
    36073606          (RW[Player].Tech[GovPreq[Subject]] < tsApplicable) then
    3608           result := eNoPreq
     3607          Result := eNoPreq
    36093608        else if Command >= sExecute then
    36103609        begin
     
    36143613            then
    36153614              RW[p1].EnemyReport[Player].Government := Subject;
    3616         end
     3615        end;
    36173616      end;
    36183617
     
    36213620{$IFDEF TEXTLOG}CmdInfo := Format('SetRates P%d: %d/%d', [Player, Subject and $F * 10, Subject shr 4 * 10]); {$ENDIF}
    36223621        if Subject and $F + Subject shr 4 > 10 then
    3623           result := eInvalid
     3622          Result := eInvalid
    36243623        else if (RW[Player].TaxRate = Subject and $F * 10) and
    36253624          (RW[Player].LuxRate = Subject shr 4 * 10) then
    3626           result := eNotChanged
     3625          Result := eNotChanged
    36273626        else if Command >= sExecute then
    36283627        begin
    36293628          RW[Player].TaxRate := Subject and $F * 10;
    36303629          RW[Player].LuxRate := Subject shr 4 * 10;
    3631         end
     3630        end;
    36323631      end;
    36333632
     
    36363635{$IFDEF TEXTLOG}CmdInfo := Format('Revolution P%d', [Player]); {$ENDIF}
    36373636        if RW[Player].Government = gAnarchy then
    3638           result := eInvalid
     3637          Result := eInvalid
    36393638        else
    36403639        begin
     
    36583657          if (Mode = moPlaying) and (Subject = adMilitary) and
    36593658            (DevModelTurn[Player] <> GTurn) then
    3660             result := eNoModel
     3659            Result := eNoModel
    36613660          else if Subject <> adMilitary then
    36623661          begin
     
    36643663            begin
    36653664              if Tech[Subject] >= MaxFutureTech_Computing then
    3666                 result := eInvalid;
     3665                Result := eInvalid;
    36673666            end
    36683667            else if Subject in FutureTech then
    36693668            begin
    36703669              if Tech[Subject] >= MaxFutureTech then
    3671                 result := eInvalid;
     3670                Result := eInvalid;
    36723671            end
    36733672            else if Tech[Subject] >= tsApplicable then
    3674               result := eInvalid; // already discovered
     3673              Result := eInvalid; // already discovered
    36753674            if Tech[Subject] <> tsSeen then // look if preqs met
    36763675              if AdvPreq[Subject, 2] <> preNone then
    36773676              begin // 2 of 3 required
    3678                 i := 0;
    3679                 for j := 0 to 2 do
    3680                   if Tech[AdvPreq[Subject, j]] >= tsApplicable then
    3681                     inc(i);
    3682                 if i < 2 then
    3683                   result := eNoPreq;
     3677                I := 0;
     3678                for J := 0 to 2 do
     3679                  if Tech[AdvPreq[Subject, J]] >= tsApplicable then
     3680                    Inc(I);
     3681                if I < 2 then
     3682                  Result := eNoPreq;
    36843683              end
    36853684              else if (AdvPreq[Subject, 0] <> preNone) and
     
    36873686                (AdvPreq[Subject, 1] <> preNone) and
    36883687                (Tech[AdvPreq[Subject, 1]] < tsApplicable) then
    3689                 result := eNoPreq;
     3688                Result := eNoPreq;
    36903689          end;
    3691           if (result = eOK) and (Command >= sExecute) then
     3690          if (Result = eOK) and (Command >= sExecute) then
    36923691          begin
    36933692            if (Mode = moPlaying) and (Subject = adMilitary) then
     
    36983697        end
    36993698        else
    3700           result := eViolation;
     3699          Result := eViolation;
    37013700      end;
    37023701
     
    37063705        {$ENDIF}
    37073706        if RW[Player].Happened and phStealTech = 0 then
    3708           result := eInvalid
     3707          Result := eInvalid
    37093708        else if (Subject >= nAdv) or (Subject in FutureTech) or
    37103709          (RW[Player].Tech[Subject] >= tsSeen) or
    37113710          (RW[GStealFrom].Tech[Subject] < tsApplicable) then
    3712           result := eInvalid
     3711          Result := eInvalid
    37133712        else if Command >= sExecute then
    37143713        begin
    37153714          SeeTech(Player, Subject);
    3716           dec(RW[Player].Happened, phStealTech);
     3715          Dec(RW[Player].Happened, phStealTech);
    37173716        end;
    37183717      end;
     
    37253724        if (Subject >= nAttitude) or (p1 >= nPl) or
    37263725          (RW[Player].EnemyReport[p1] = nil) then
    3727           result := eInvalid
     3726          Result := eInvalid
    37283727        else if RW[Player].Treaty[p1] = trNoContact then
    3729           result := eNoPreq
     3728          Result := eNoPreq
    37303729        else if RW[Player].Attitude[p1] = Subject then
    3731           result := eNotChanged
     3730          Result := eNotChanged
    37323731        else if Command >= sExecute then
    37333732        begin
     
    37403739      if (LastEndClientCommand <> scReject) or
    37413740        (RW[Player].Treaty[pContacted] < trPeace) then
    3742         result := eInvalid
     3741        Result := eInvalid
    37433742      else if (ServerVersion[Player] >= $010100) and
    37443743        (GTurn < RW[Player].LastCancelTreaty[pContacted] + CancelTreatyTurns)
    37453744      then
    3746         result := eCancelTreatyRush
     3745        Result := eCancelTreatyRush
    37473746      else if Command >= sExecute then
    37483747      begin
     
    37523751          if (p2 <> pContacted) and (1 shl p2 and PeaceEnded <> 0) then
    37533752          begin
    3754             i := pContacted shl 4 + Player;
    3755             CallPlayer(cShowSupportAllianceAgainst, p2, i);
     3753            I := pContacted shl 4 + Player;
     3754            CallPlayer(cShowSupportAllianceAgainst, p2, I);
    37563755          end;
    37573756        for p2 := 0 to nPl - 1 do
    37583757          if (p2 <> pContacted) and (1 shl p2 and PeaceEnded <> 0) then
    37593758          begin
    3760             i := p2;
    3761             CallPlayer(cShowCancelTreatyByAlliance, Player, i);
     3759            I := p2;
     3760            CallPlayer(cShowCancelTreatyByAlliance, Player, I);
    37623761          end;
    37633762        LastEndClientCommand := sTurn;
     
    37723771{$IFDEF TEXTLOG}CmdInfo := Format('CreateDevModel P%d', [Player]); {$ENDIF}
    37733772        if Subject >= 4 then
    3774           result := eInvalid
     3773          Result := eInvalid
    37753774        else if (upgrade[Subject, 0].Preq <> preNone) and
    37763775          (RW[Player].Tech[upgrade[Subject, 0].Preq] < tsApplicable) then
    3777           result := eNoPreq
     3776          Result := eNoPreq
    37783777        else if Command >= sExecute then
    37793778        begin
     
    37863785            Upgrades := 0;
    37873786            FutureMCost := 0;
    3788             for i := 0 to nUpgrade - 1 do
    3789               with upgrade[Domain, i] do
     3787            for I := 0 to nUpgrade - 1 do
     3788              with upgrade[Domain, I] do
    37903789                if (Preq = preNone) or (Preq >= 0) and
    37913790                  ((RW[Player].Tech[Preq] >= tsApplicable) or
     
    37943793                  if Preq in FutureTech then
    37953794                  begin
    3796                     j := RW[Player].Tech[Preq];
    3797                     inc(FutureMCost, j * Cost);
     3795                    J := RW[Player].Tech[Preq];
     3796                    Inc(FutureMCost, J * Cost);
    37983797                  end
    37993798                  else
    38003799                  begin
    3801                     j := 1;
     3800                    J := 1;
    38023801                    if Cost > MCost then
    38033802                      MCost := Cost;
    38043803                  end;
    3805                   inc(Upgrades, 1 shl i);
    3806                   inc(MStrength, j * Strength);
    3807                   inc(MTrans, j * Trans);
     3804                  Inc(Upgrades, 1 shl I);
     3805                  Inc(MStrength, J * Strength);
     3806                  Inc(MTrans, J * Trans);
    38083807                end;
    3809             inc(MCost, FutureMCost);
     3808            Inc(MCost, FutureMCost);
    38103809            FillChar(Cap, SizeOf(Cap), 0);
    38113810            Cap[mcOffense] := 2;
    38123811            Cap[mcDefense] := 1;
    3813             for i := 0 to nFeature - 1 do
    3814               with Feature[i] do
     3812            for I := 0 to nFeature - 1 do
     3813              with Feature[I] do
    38153814                if (1 shl Domain and Domains <> 0) and
    38163815                  ((Preq = preNone) or (Preq = preSun) and
    38173816                  (GWonder[woSun].EffectiveOwner = Player) or (Preq >= 0) and
    3818                   (RW[Player].Tech[Preq] >= tsApplicable)) and (i in AutoFeature)
     3817                  (RW[Player].Tech[Preq] >= tsApplicable)) and (I in AutoFeature)
    38193818                then
    3820                   Cap[i] := 1;
     3819                  Cap[I] := 1;
    38213820            MaxWeight := 5;
    38223821            if (WeightPreq7[Domain] <> preNA) and
     
    38403839{$IFDEF TEXTLOG}CmdInfo := Format('SetDevModelCap P%d', [Player]); {$ENDIF}
    38413840        if Subject >= nFeature then
    3842           result := eInvalid
     3841          Result := eInvalid
    38433842        else if DevModelTurn[Player] = GTurn then
    38443843        begin
     
    38463845          with RW[Player].DevModel do
    38473846            if 1 shl Domain and Feature[Subject].Domains = 0 then
    3848               result := eDomainMismatch
     3847              Result := eDomainMismatch
    38493848            else if not((Feature[Subject].Preq = preNone) or
    38503849              (Feature[Subject].Preq = preSun) and
     
    38523851              (Feature[Subject].Preq >= 0) and
    38533852              (RW[Player].Tech[Feature[Subject].Preq] >= tsApplicable)) then
    3854               result := eNoPreq
     3853              Result := eNoPreq
    38553854            else
    38563855            begin
     
    38683867                  MaxCap := 3;
    38693868                if RW[Player].Tech[adSteel] >= tsApplicable then
    3870                   inc(MaxCap);
     3869                  Inc(MaxCap);
    38713870              end
    38723871              else
     
    38783877              if (NewCap < MinCap) or (NewCap > MaxCap) or
    38793878                (Weight + (NewCap - Cap[Subject]) * CapWeight > MaxWeight) then
    3880                 result := eViolation
     3879                Result := eViolation
    38813880              else if Command >= sExecute then
    38823881              begin
     
    39213920        end
    39223921        else
    3923           result := eNoModel;
     3922          Result := eNoModel;
    39243923      end;
    39253924
     
    39323931{$IFDEF TEXTLOG}CmdInfo := Format('RemoveUnit P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF}
    39333932        if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then
    3934           result := eInvalid
     3933          Result := eInvalid
    39353934        else
    39363935        begin
    3937           result := eRemoved;
     3936          Result := eRemoved;
    39383937          Loc0 := RW[Player].Un[Subject].Loc;
    39393938          if RealMap[Loc0] and fCity <> 0 then { check utilize }
     
    39473946                (Project and cpImp = 0) and
    39483947                (RW[Player].Model[Project and cpIndex].Kind <> mkCaravan) then
    3949                 result := eUtilized;
     3948                Result := eUtilized;
    39503949              if Command >= sExecute then
    39513950              begin
    3952                 if result = eUtilized then
     3951                if Result = eUtilized then
    39533952                begin
    39543953                  with RW[Player].Un[Subject] do
    39553954                  begin
    3956                     Cost := integer(RW[Player].Model[mix].Cost) * Health *
     3955                    Cost := Integer(RW[Player].Model[mix].Cost) * Health *
    39573956                      BuildCostMod[Difficulty[Player]] div 1200;
    39583957                    if RW[Player].Model[mix].Cap[mcLine] > 0 then
     
    39603959                  end;
    39613960                  if Project and (cpImp + cpIndex) = cpImp + imTrGoods then
    3962                     inc(RW[Player].Money, Cost)
     3961                    Inc(RW[Player].Money, Cost)
    39633962                  else
    39643963                  begin
    3965                     inc(Prod, Cost * 2 div 3);
     3964                    Inc(Prod, Cost * 2 div 3);
    39663965                    Project0 := Project0 and not cpCompleted;
    39673966                    if Project0 and not cpAuto <> Project and not cpAuto then
     
    39833982{$IFDEF TEXTLOG}CmdInfo := Format('SetUnitHome P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF}
    39843983        if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then
    3985           result := eInvalid
     3984          Result := eInvalid
    39863985        else
    39873986        begin
    39883987          Loc0 := RW[Player].Un[Subject].Loc;
    39893988          if RealMap[Loc0] and fCity = 0 then
    3990             result := eInvalid
     3989            Result := eInvalid
    39913990          else
    39923991          begin
    39933992            SearchCity(Loc0, Player, cix1);
    39943993            if RW[Player].City[cix1].Flags and chCaptured <> 0 then
    3995               result := eViolation
     3994              Result := eViolation
    39963995            else if Command >= sExecute then
    39973996              RW[Player].Un[Subject].Home := cix1;
     
    40104009{$IFDEF TEXTLOG}CmdInfo := Format('LoadUnit P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF}
    40114010        if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then
    4012           result := eInvalid
     4011          Result := eInvalid
    40134012        else
    4014           result := LoadUnit(Player, Subject, Command < sExecute);
     4013          Result := LoadUnit(Player, Subject, Command < sExecute);
    40154014      end;
    40164015
     
    40194018{$IFDEF TEXTLOG}CmdInfo := Format('UnloadUnit P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF}
    40204019        if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then
    4021           result := eInvalid
     4020          Result := eInvalid
    40224021        else
    4023           result := UnloadUnit(Player, Subject, Command < sExecute);
     4022          Result := UnloadUnit(Player, Subject, Command < sExecute);
    40244023      end;
    40254024
    40264025    sSelectTransport, sSelectTransport - sExecute:
    40274026      if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then
    4028         result := eInvalid
     4027        Result := eInvalid
    40294028      else
    40304029        with RW[Player].Model[RW[Player].Un[Subject].mix] do
    40314030        begin
    40324031          if Cap[mcSeaTrans] + Cap[mcAirTrans] + Cap[mcCarrier] = 0 then
    4033             result := eInvalid
     4032            Result := eInvalid
    40344033          else if Command >= sExecute then
    40354034            uixSelectedTransport := Subject;
     
    40424041      begin
    40434042        p1 := Command shr 4 and $F;
    4044         Loc1 := integer(Data);
     4043        Loc1 := Integer(Data);
    40454044        if (Occupant[Loc1] >= 0) and (p1 <> Occupant[Loc1]) or
    40464045          (RealMap[Loc1] and fCity <> 0) and
    40474046          (RealMap[Loc1] shr 27 <> Cardinal(p1)) or
    40484047          (RW[p1].Model[Subject].Domain < dAir) and
    4049           ((RW[p1].Model[Subject].Domain = dSea) <> (RealMap[integer(Data)] and
     4048          ((RW[p1].Model[Subject].Domain = dSea) <> (RealMap[Integer(Data)] and
    40504049          fTerrain < fGrass)) then
    4051           result := eViolation
     4050          Result := eViolation
    40524051        else if Command >= sExecute then
    40534052        begin
    40544053          CreateUnit(p1, Subject);
    4055           RW[p1].Un[RW[p1].nUn - 1].Loc := integer(Data);
     4054          RW[p1].Un[RW[p1].nUn - 1].Loc := Integer(Data);
    40564055          PlaceUnit(p1, RW[p1].nUn - 1);
    4057           UpdateUnitMap(integer(Data));
     4056          UpdateUnitMap(Integer(Data));
    40584057        end;
    40594058      end
    40604059      else
    4061         result := eInvalid;
     4060        Result := eInvalid;
    40624061
    40634062    sMoveUnit + (0 + 6 * 8) * 16, sMoveUnit + (1 + 7 * 8) * 16,
     
    40764075{$IFDEF TEXTLOG}CmdInfo := Format('MoveUnit P%d I%d Mod%d Loc%d (%d,%d)', [Player, Subject, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc, dx, dy]); {$ENDIF}
    40774076        if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then
    4078           result := eInvalid
     4077          Result := eInvalid
    40794078        else
    4080           result := MoveUnit(Player, Subject, dx, dy, Command < sExecute);
     4079          Result := MoveUnit(Player, Subject, dx, dy, Command < sExecute);
    40814080      end;
    40824081
     
    40894088{$IFDEF TEXTLOG}CmdInfo := Format('AddToCity P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF}
    40904089        if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then
    4091           result := eInvalid
     4090          Result := eInvalid
    40924091        else if not(RW[Player].Model[RW[Player].Un[Subject].mix].Kind
    40934092          in [mkSettler, mkSlaves]) and
    40944093          (RW[Player].Un[Subject].Flags and unConscripts = 0) then
    4095           result := eViolation
     4094          Result := eViolation
    40964095        else
    40974096        begin
    40984097          Loc0 := RW[Player].Un[Subject].Loc;
    40994098          if RealMap[Loc0] and fCity = 0 then
    4100             result := eInvalid
     4099            Result := eInvalid
    41014100          else
    41024101          begin
     
    41044103            with RW[Player].City[cix1] do
    41054104              if not CanCityGrow(Player, cix1) then
    4106                 result := eMaxSize
     4105                Result := eMaxSize
    41074106              else if Command >= sExecute then
    41084107              begin { add to city }
     
    41244123      begin
    41254124        Loc0 := RW[Player].Un[Subject].Loc;
    4126         i := Command shr 4 and $3F; // new job
    4127 {$IFDEF TEXTLOG}CmdInfo := Format('StartJob P%d Mod%d Loc%d: %d', [Player, RW[Player].Un[Subject].mix, Loc0, i]); {$ENDIF}
     4125        I := Command shr 4 and $3F; // new job
     4126{$IFDEF TEXTLOG}CmdInfo := Format('StartJob P%d Mod%d Loc%d: %d', [Player, RW[Player].Un[Subject].mix, Loc0, I]); {$ENDIF}
    41284127        if (Subject >= RW[Player].nUn) or (Loc0 < 0) then
    4129           result := eInvalid
    4130         else if i >= nJob then
    4131           result := eInvalid
     4128          Result := eInvalid
     4129        else if I >= nJob then
     4130          Result := eInvalid
    41324131        else
    41334132        begin
    4134           result := StartJob(Player, Subject, i, Command < sExecute);
    4135           if result = eCity then
     4133          Result := StartJob(Player, Subject, I, Command < sExecute);
     4134          if Result = eCity then
    41364135          begin // new city
    41374136            cix1 := RW[Player].nCity - 1;
     
    41584157    sSetCityProject, sSetCityProject - sExecute:
    41594158      begin
    4160         NewProject := integer(Data) and not cpAuto;
     4159        NewProject := Integer(Data) and not cpAuto;
    41614160{$IFDEF TEXTLOG}CmdInfo := Format('SetCityProject P%d Loc%d: %d', [Player, RW[Player].City[Subject].Loc, NewProject]); {$ENDIF}
    41624161        if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0)
    41634162        then
    4164           result := eInvalid
     4163          Result := eInvalid
    41654164        else
    41664165          with RW[Player].City[Subject] do
    41674166          begin
    41684167            if NewProject = Project then
    4169               result := eNotChanged
     4168              Result := eNotChanged
    41704169            else
    41714170            begin
     
    41754174              begin
    41764175                if NewProject and cpIndex >= RW[Player].nModel then
    4177                   result := eInvalid
     4176                  Result := eInvalid
    41784177                else if (NewProject and cpConscripts <> 0) and
    41794178                  not((RW[Player].Tech[adConscription] >= tsApplicable) and
     
    41814180                  and (RW[Player].Model[NewProject and cpIndex].Kind < mkScout))
    41824181                then
    4183                   result := eViolation
     4182                  Result := eViolation
    41844183                  // else if (RW[Player].Model[NewProject and cpIndex].Kind=mkSlaves)
    41854184                  // and (GWonder[woPyramids].EffectiveOwner<>Player) then
     
    41874186              end
    41884187              else if NewProject and cpIndex >= nImp then
    4189                 result := eInvalid
     4188                Result := eInvalid
    41904189              else
    41914190              begin
    41924191                Preq := Imp[NewProject and cpIndex].Preq;
    4193                 for i := 0 to nImpReplacement - 1 do
    4194                   if (ImpReplacement[i].OldImp = NewProject and cpIndex) and
    4195                     (built[ImpReplacement[i].NewImp] > 0) then
    4196                     result := eObsolete;
    4197                 if result = eObsolete then
     4192                for I := 0 to nImpReplacement - 1 do
     4193                  if (ImpReplacement[I].OldImp = NewProject and cpIndex) and
     4194                    (built[ImpReplacement[I].NewImp] > 0) then
     4195                    Result := eObsolete;
     4196                if Result = eObsolete then
    41984197                else if Preq = preNA then
    4199                   result := eInvalid
     4198                  Result := eInvalid
    42004199                else if (Preq >= 0) and (RW[Player].Tech[Preq] < tsApplicable)
    42014200                then
    4202                   result := eNoPreq
     4201                  Result := eNoPreq
    42034202                else if built[NewProject and cpIndex] > 0 then
    4204                   result := eInvalid
     4203                  Result := eInvalid
    42054204                else if (NewProject and cpIndex < nWonder) and
    42064205                  (GWonder[NewProject and cpIndex].CityID <> WonderNotBuiltYet) then
    4207                   result := eViolation // wonder already exists
     4206                  Result := eViolation // wonder already exists
    42084207                else if (NewProject and cpIndex = imSpacePort) and
    42094208                  (RW[Player].NatBuilt[imSpacePort] > 0) then
    4210                   result := eViolation // space port already exists
     4209                  Result := eViolation // space port already exists
    42114210                else if (NewProject = cpImp + imBank) and (built[imMarket] = 0)
    42124211                  or (NewProject = cpImp + imUniversity) and
     
    42144213                  (built[imUniversity] = 0) or (NewProject = cpImp + imMfgPlant)
    42154214                  and (built[imFactory] = 0) then
    4216                   result := eNoPreq;
     4215                  Result := eNoPreq;
    42174216                case NewProject - cpImp of
    42184217                  woLighthouse, woMagellan, imCoastalFort, imHarbor, imPlatform:
     
    42254224                        if (Loc1 >= 0) and (Loc1 < MapSize) and
    42264225                          (RealMap[Loc1] and fTerrain = fShore) then
    4227                           inc(Preq);
     4226                          Inc(Preq);
    42284227                      end;
    42294228                      if Preq = 0 then
    4230                         result := eNoPreq;
     4229                        Result := eNoPreq;
    42314230                    end;
    42324231                  woHoover, imHydro:
     
    42404239                          ((RealMap[Loc1] and fTerrain = fMountains) or
    42414240                          (RealMap[Loc1] and fRiver <> 0)) then
    4242                           inc(Preq);
     4241                          Inc(Preq);
    42434242                      end;
    42444243                      if Preq = 0 then
    4245                         result := eNoPreq;
     4244                        Result := eNoPreq;
    42464245                    end;
    42474246                  woMIR, imShipComp, imShipPow, imShipHab:
    42484247                    if RW[Player].NatBuilt[imSpacePort] = 0 then
    4249                       result := eNoPreq;
     4248                      Result := eNoPreq;
    42504249                end;
    42514250                if (GTestFlags and tfNoRareNeed = 0) and
    42524251                  (Imp[NewProject and cpIndex].Kind = ikShipPart) then
    42534252                  if RW[Player].Tech[adMassProduction] < tsApplicable then
    4254                     result := eNoPreq
     4253                    Result := eNoPreq
    42554254                  else
    42564255                  begin // check for rare resources
    42574256                    if NewProject and cpIndex = imShipComp then
    4258                       j := 1
     4257                      J := 1
    42594258                    else if NewProject and cpIndex = imShipPow then
    4260                       j := 2
     4259                      J := 2
    42614260                    else { if NewProject and cpIndex=imShipHab then }
    4262                       j := 3;
     4261                      J := 3;
    42634262                    // j = rare resource required
    42644263                    Preq := 0;
     
    42684267                      Loc1 := Radius[V21];
    42694268                      if (Loc1 >= 0) and (Loc1 < MapSize) and
    4270                         (RealMap[Loc1] shr 25 and 3 = Cardinal(j)) then
    4271                         inc(Preq);
     4269                        (RealMap[Loc1] shr 25 and 3 = Cardinal(J)) then
     4270                        Inc(Preq);
    42724271                    end;
    42734272                    if Preq = 0 then
    4274                       result := eNoPreq;
     4273                      Result := eNoPreq;
    42754274                  end;
    42764275              end;
    42774276
    4278               if (Command >= sExecute) and (result >= rExecuted) then
     4277              if (Command >= sExecute) and (Result >= rExecuted) then
    42794278              begin
    42804279                if pt0 <> ptSelect then
     
    42854284                    and (pt0 <> ptCaravan) then
    42864285                  begin
    4287                     inc(RW[Player].Money, Prod0);
     4286                    Inc(RW[Player].Money, Prod0);
    42884287                    Prod := 0;
    42894288                    Prod0 := 0;
     
    42924291                  else
    42934292                    Prod := Prod0 * 2 div 3;
    4294                 Project := NewProject
     4293                Project := NewProject;
    42954294              end;
    42964295            end;
     
    43034302        if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0)
    43044303        then
    4305           result := eInvalid
     4304          Result := eInvalid
    43064305        else
    43074306          with RW[Player].City[Subject] do
    43084307            if (RW[Player].Government = gAnarchy) or (Flags and chCaptured <> 0)
    43094308            then
    4310               result := eOutOfControl
     4309              Result := eOutOfControl
    43114310            else if (Project and cpImp <> 0) and
    43124311              ((Project and cpIndex = imTrGoods) or
    43134312              (Imp[Project and cpIndex].Kind = ikShipPart)) then
    4314               result := eInvalid // don't buy colony ship
     4313              Result := eInvalid // don't buy colony ship
    43154314            else
    43164315            begin
     
    43314330                Cost := Cost * 4;
    43324331              if Cost <= 0 then
    4333                 result := eNotChanged
     4332                Result := eNotChanged
    43344333              else if Cost > RW[Player].Money then
    4335                 result := eViolation
     4334                Result := eViolation
    43364335              else if Command >= sExecute then
    43374336                IntServer(sIntBuyMaterial, Player, Subject, Cost);
     
    43464345        if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0)
    43474346        then
    4348           result := eInvalid
     4347          Result := eInvalid
    43494348        else if Command >= sExecute then
    43504349          with RW[Player].City[Subject] do
    43514350          begin
    4352             inc(RW[Player].Money, Prod0);
     4351            Inc(RW[Player].Money, Prod0);
    43534352            Prod := 0;
    43544353            Prod0 := 0;
     
    43584357    sSellCityImprovement, sSellCityImprovement - sExecute:
    43594358      begin
    4360 {$IFDEF TEXTLOG}CmdInfo := Format('SellCityImprovement P%d Loc%d: %d', [Player, RW[Player].City[Subject].Loc, integer(Data)]); {$ENDIF}
     4359{$IFDEF TEXTLOG}CmdInfo := Format('SellCityImprovement P%d Loc%d: %d', [Player, RW[Player].City[Subject].Loc, Integer(Data)]); {$ENDIF}
    43614360        if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0)
    43624361        then
    4363           result := eInvalid
     4362          Result := eInvalid
    43644363        else
    43654364          with RW[Player].City[Subject] do
    4366             if built[integer(Data)] = 0 then
    4367               result := eInvalid
     4365            if built[Integer(Data)] = 0 then
     4366              Result := eInvalid
    43684367            else if (RW[Player].Government = gAnarchy) or
    43694368              (Flags and chCaptured <> 0) then
    4370               result := eOutOfControl
     4369              Result := eOutOfControl
    43714370            else if Flags and chImprovementSold <> 0 then
    4372               result := eOnlyOnce
     4371              Result := eOnlyOnce
    43734372            else if Command >= sExecute then
    43744373            begin
    4375               inc(RW[Player].Money, Imp[integer(Data)].Cost * BuildCostMod
     4374              Inc(RW[Player].Money, Imp[Integer(Data)].Cost * BuildCostMod
    43764375                [Difficulty[Player]] div 12);
    4377               built[integer(Data)] := 0;
    4378               if Imp[integer(Data)].Kind in [ikNatLocal, ikNatGlobal] then
     4376              built[Integer(Data)] := 0;
     4377              if Imp[Integer(Data)].Kind in [ikNatLocal, ikNatGlobal] then
    43794378              begin
    4380                 RW[Player].NatBuilt[integer(Data)] := 0;
    4381                 case integer(Data) of
     4379                RW[Player].NatBuilt[Integer(Data)] := 0;
     4380                case Integer(Data) of
    43824381                  imGrWall:
    43834382                    GrWallContinent[Player] := -1;
     
    43864385                end;
    43874386              end;
    4388               inc(Flags, chImprovementSold);
     4387              Inc(Flags, chImprovementSold);
    43894388            end;
    43904389      end;
     
    43924391    sRebuildCityImprovement, sRebuildCityImprovement - sExecute:
    43934392      begin
    4394         OldImp := integer(Data);
     4393        OldImp := Integer(Data);
    43954394{$IFDEF TEXTLOG}CmdInfo := Format('RebuildCityImprovement P%d Loc%d: %d', [Player, RW[Player].City[Subject].Loc, OldImp]); {$ENDIF}
    43964395        if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0)
    43974396        then
    4398           result := eInvalid
     4397          Result := eInvalid
    43994398        else
    44004399        begin
    44014400          if (OldImp < 0) or (OldImp >= nImp) or
    44024401            not(Imp[OldImp].Kind in [ikCommon, ikNatLocal, ikNatGlobal]) then
    4403             result := eInvalid
     4402            Result := eInvalid
    44044403          else
    44054404            with RW[Player].City[Subject] do
     
    44074406                not(Imp[Project and cpIndex].Kind in [ikCommon, ikNatLocal,
    44084407                ikNatGlobal]) then
    4409                 result := eInvalid
     4408                Result := eInvalid
    44104409              else if (RW[Player].Government = gAnarchy) or
    44114410                (Flags and chCaptured <> 0) then
    4412                 result := eOutOfControl
     4411                Result := eOutOfControl
    44134412              else if Flags and chImprovementSold <> 0 then
    4414                 result := eOnlyOnce
     4413                Result := eOnlyOnce
    44154414              else if Command >= sExecute then
    44164415              begin
    4417                 inc(Prod, Imp[OldImp].Cost * BuildCostMod[Difficulty[Player]]
     4416                Inc(Prod, Imp[OldImp].Cost * BuildCostMod[Difficulty[Player]]
    44184417                  div 12 * 2 div 3);
    44194418                Project0 := Project0 and not cpCompleted;
     
    44324431                  end;
    44334432                end;
    4434                 inc(Flags, chImprovementSold);
     4433                Inc(Flags, chImprovementSold);
    44354434              end;
    44364435        end;
     
    44394438    sSetCityTiles, sSetCityTiles - sExecute:
    44404439      begin
    4441 {$IFDEF TEXTLOG}CmdInfo := Format('SetCityTiles P%d Loc%d: %x', [Player, RW[Player].City[Subject].Loc, integer(Data)]); {$ENDIF}
     4440{$IFDEF TEXTLOG}CmdInfo := Format('SetCityTiles P%d Loc%d: %x', [Player, RW[Player].City[Subject].Loc, Integer(Data)]); {$ENDIF}
    44424441        if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0)
    44434442        then
    4444           result := eInvalid
     4443          Result := eInvalid
    44454444        else
    4446           result := SetCityTiles(Player, Subject, integer(Data),
     4445          Result := SetCityTiles(Player, Subject, Integer(Data),
    44474446            Command < sExecute);
    44484447      end;
     
    44614460    end
    44624461    else
    4463       result := eUnknown;
     4462      Result := eUnknown;
    44644463  end; { case command }
    44654464
    44664465  // do not log invalid and non-relevant commands
    4467   if result = eZOC_EnemySpotted then
     4466  if Result = eZOC_EnemySpotted then
    44684467  begin
    4469     assert(Mode = moPlaying);
     4468    Assert(Mode = moPlaying);
    44704469    CL.State := FormerCLState;
    44714470    IntServer(sIntDiscoverZOC, Player, 0, ZOCTile);
    44724471  end
    4473   else if result and rEffective = 0 then
     4472  else if Result and rEffective = 0 then
    44744473    if Mode < moPlaying then
    44754474    begin
    4476 {$IFDEF TEXTLOG}CmdInfo := Format('***ERROR (%x) ', [result]) + CmdInfo;
     4475{$IFDEF TEXTLOG}CmdInfo := Format('***ERROR (%x) ', [Result]) + CmdInfo;
    44774476      {$ENDIF}
    4478       LoadOK := false;
     4477      LoadOK := False;
    44794478    end
    44804479    else
     
    44824481      if logged then
    44834482        CL.State := FormerCLState;
    4484       if (result < rExecuted) and (Command >= sExecute) then
     4483      if (Result < rExecuted) and (Command >= sExecute) then
    44854484        PutMessage(1 shl 16 + 1, Format('INVALID: %d calls %x (%d)',
    44864485          [Player, Command, Subject]));
     
    44884487
    44894488  if (Command and (cClientEx or sExecute or sctMask) = sExecute or sctEndClient)
    4490     and (result >= rExecuted) then
     4489    and (Result >= rExecuted) then
    44914490    LastEndClientCommand := Command;
    4492 {$IFOPT O-}dec(nHandoverStack, 2); {$ENDIF}
    4493 end; { <<<server }
     4491{$IFOPT O-}Dec(nHandoverStack, 2); {$ENDIF}
     4492end;
    44944493
    44954494
Note: See TracChangeset for help on using the changeset viewer.