Changeset 447 for trunk/GameServer.pas


Ignore:
Timestamp:
May 19, 2022, 10:39:34 PM (2 years ago)
Author:
chronos
Message:
  • Modified: Use first capital letter in identifiers.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GameServer.pas

    r442 r447  
    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}
     
    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 }
     552    S := 'cEvoMap'#0;
     553    MapFile.write(S[1], 8); { file id }
     554    I := 0;
     555    MapFile.write(I, 4); { format id }
    556556    MapFile.write(MaxTurn, 4);
    557557    MapFile.write(lx, 4);
     
    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
     580      MapFile.read(I, 4); // MaxTurn
    581581      MapFile.read(lx, 4);
    582582      MapFile.read(ly, 4);
     
    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;
     
    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 }
     642  S := 'cEvoBook';
     643  LogFile.write(S[1], 8); { file id }
     644  I := CevoVersion;
     645  LogFile.write(I, 4); { c-evo version }
    646646  LogFile.write(ExeInfo.Time, 4);
    647647  LogFile.write(lx, 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
    662662    LogFile.write(SaveMap, ((MapSize - 1) div 4 + 1) * 4);
    663   for i := 0 to nPl - 1 do
    664     if not Assigned(bix[i]) then
     663  for I := 0 to nPl - 1 do
     664    if not Assigned(bix[I]) then
    665665      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
     
    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;
     836          RW[P].DefaultDebugMap := nil;
    837837
    838838        { !!!for i:=0 to nShipPart-1 do GShip[p].Parts[i]:=Delphirandom((3-i)*2); }
     
    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;
     
    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);
     
    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}
     
    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
     
    18241824          DiscoverTech(pTurn, ResearchTech);
    18251825
    1826         dec(Research, Cost);
     1826        Dec(Research, Cost);
    18271827        Happened := Happened or phTech;
    18281828        ResearchTech := -1;
     
    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);
     
    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
     
    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
     
    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;
    22912291end;
    22922292
    2293 function ExecuteAttack(p, uix, ToLoc: integer; var MoveInfo: TMoveInfo;
    2294   ShowMove: TShowMove): integer;
     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
     
    25612561end;
    25622562
    2563 function MoveUnit(p, uix, dx, dy: integer; TestOnly: boolean): integer;
     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;
     
    26142614end;
    26152615
    2616 function Server(Command, Player, Subject: integer; var Data): integer; stdcall;
    2617 
    2618   function CountPrice(const Offer: TOffer; PriceType: integer): integer;
     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;
     
    27082708  end;
    27092709
    2710   assert(MapSize = lx * ly);
    2711   assert(Command and (sctMask or sExecute) <> sctInternal or sExecute);
     2710  Assert(MapSize = lx * ly);
     2711  Assert(Command and (sctMask or sExecute) <> sctInternal or sExecute);
    27122712  // not for internal commands
    27132713  if (Command < 0) or (Command >= $10000) then
    27142714  begin
    2715     result := eUnknown;
    2716     exit;
     2715    Result := eUnknown;
     2716    Exit;
    27172717  end;
    27182718
     
    27212721    ((Subject < 0) or (Subject >= $1000))) then
    27222722  begin
    2723     result := eInvalid;
    2724     exit;
     2723    Result := eInvalid;
     2724    Exit;
    27252725  end;
    27262726
     
    27312731  begin
    27322732    PutMessage(1 shl 16 + 1, Format('NOT Alive: %d', [Player]));
    2733     result := eNoTurn;
    2734     exit;
     2733    Result := eNoTurn;
     2734    Exit;
    27352735  end;
    27362736
    2737   result := eOK;
     2737  Result := eOK;
    27382738
    27392739  // check if command allowed now
     
    27582758    PutMessage(1 shl 16 + 1, Format('No Turn: %d calls %x',
    27592759      [Player, Command shr 4]));
    2760     result := eNoTurn;
    2761     exit;
     2760    Result := eNoTurn;
     2761    Exit;
    27622762  end;
    27632763
     
    27672767  HandoverStack[nHandoverStack] := Player + $1000;
    27682768  HandoverStack[nHandoverStack + 1] := Command;
    2769   inc(nHandoverStack, 2);
     2769  Inc(nHandoverStack, 2);
    27702770
    27712771  InvalidTreatyMap := 0;
     
    27802780    FormerCLState := CL.State;
    27812781    CL.Put(Command, Player, Subject, @Data);
    2782     logged := true;
     2782    logged := True;
    27832783  end
    27842784  else
    2785     logged := false;
     2785    logged := False;
    27862786
    27872787  case Command of
     
    27982798
    27992799    sGetDebugMap:
    2800       pointer(Data) := DebugMap[Subject];
     2800      Pointer(Data) := DebugMap[Subject];
    28012801
    28022802    { sChangeSuperView:
    28032803      if Difficulty[Player]=0 then
    28042804      begin
    2805       for i:=0 to nBrain-1 do if Brain[i].Initialized then
    2806       CallClient(i, cShowSuperView, Subject)
     2805      for I:=0 to nBrain-1 do if Brain[I].Initialized then
     2806      CallClient(I, cShowSuperView, Subject)
    28072807      end
    2808       else result:=eInvalid; }
     2808      else Result:=eInvalid; }
    28092809
    28102810    sRefreshDebugMap:
     
    28292829          else
    28302830            StopTurn := RW[Player].EnemyReport[Subject].TurnOfCivilReport + 1;
    2831         move(Stat[Command shr 4 and $F, Subject]^, Data,
    2832           StopTurn * SizeOf(integer));
     2831        Move(Stat[Command shr 4 and $F, Subject]^, Data,
     2832          StopTurn * SizeOf(Integer));
    28332833        FillChar(TChart(Data)[StopTurn], (GTurn - StopTurn) *
    2834           SizeOf(integer), 0);
     2834          SizeOf(Integer), 0);
    28352835      end
    28362836      else
    2837         result := eInvalid;
     2837        Result := eInvalid;
    28382838
    28392839    sGetTechCost:
    2840       integer(Data) := TechCost(Player);
     2840      Integer(Data) := TechCost(Player);
    28412841
    28422842    sGetAIInfo:
    28432843      if AIInfo[Subject] = '' then
    2844         pchar(Data) := nil
    2845       else
    2846         pchar(Data) := @AIInfo[Subject][1];
     2844        PChar(Data) := nil
     2845      else
     2846        PChar(Data) := @AIInfo[Subject][1];
    28472847
    28482848    sGetAICredits:
    28492849      if AICredits = '' then
    2850         pchar(Data) := nil
    2851       else
    2852         pchar(Data) := @AICredits[1];
     2850        PChar(Data) := nil
     2851      else
     2852        PChar(Data) := @AICredits[1];
    28532853
    28542854    sGetVersion:
    2855       integer(Data) := CevoVersion;
     2855      Integer(Data) := CevoVersion;
    28562856
    28572857    sGetGameChanged:
    28582858      if Player <> 0 then
    2859         result := eInvalid
     2859        Result := eInvalid
    28602860      else if (CL <> nil) and (CL.State.nLog = nLogOpened) and
    28612861        (CL.State.MoveCode = 0) and not HasCityTileChanges and
    28622862        not HasChanges(Player) then
    2863         result := eNotChanged;
     2863        Result := eNotChanged;
    28642864
    28652865    sGetTileInfo:
    28662866      if (Subject >= 0) and (Subject < MapSize) then
    2867         result := GetTileInfo(Player, -2, Subject, TTileInfo(Data))
    2868       else
    2869         result := eInvalid;
     2867        Result := GetTileInfo(Player, -2, Subject, TTileInfo(Data))
     2868      else
     2869        Result := eInvalid;
    28702870
    28712871    sGetCityTileInfo:
    28722872      if (Subject >= 0) and (Subject < MapSize) then
    2873         result := GetTileInfo(Player, -1, Subject, TTileInfo(Data))
    2874       else
    2875         result := eInvalid;
     2873        Result := GetTileInfo(Player, -1, Subject, TTileInfo(Data))
     2874      else
     2875        Result := eInvalid;
    28762876
    28772877    sGetHypoCityTileInfo:
     
    28802880        if (TTileInfo(Data).ExplCity < 0) or
    28812881          (TTileInfo(Data).ExplCity >= RW[Player].nCity) then
    2882           result := eInvalid
     2882          Result := eInvalid
    28832883        else if ObserveLevel[Subject] shr (Player * 2) and 3 = 0 then
    2884           result := eNoPreq
     2884          Result := eNoPreq
    28852885        else
    2886           result := GetTileInfo(Player, TTileInfo(Data).ExplCity, Subject,
     2886          Result := GetTileInfo(Player, TTileInfo(Data).ExplCity, Subject,
    28872887            TTileInfo(Data));
    28882888      end
    28892889      else
    2890         result := eInvalid;
     2890        Result := eInvalid;
    28912891
    28922892    sGetJobProgress:
     
    28942894      begin
    28952895        if ObserveLevel[Subject] shr (Player * 2) and 3 = 0 then
    2896           result := eNoPreq
     2896          Result := eNoPreq
    28972897        else
    2898           result := GetJobProgress(Player, Subject, TJobProgressData(Data));
     2898          Result := GetJobProgress(Player, Subject, TJobProgressData(Data));
    28992899      end
    29002900      else
    2901         result := eInvalid;
     2901        Result := eInvalid;
    29022902
    29032903    sGetModels:
     
    29112911      end
    29122912      else
    2913         result := eInvalid;
     2913        Result := eInvalid;
    29142914
    29152915    sGetUnits:
    29162916      if (Subject >= 0) and (Subject < MapSize) and
    29172917        (ObserveLevel[Subject] shr (Player * 2) and 3 = lObserveSuper) then
    2918         integer(Data) := GetUnitStack(Player, Subject)
    2919       else
    2920         result := eNoPreq;
     2918        Integer(Data) := GetUnitStack(Player, Subject)
     2919      else
     2920        Result := eNoPreq;
    29212921
    29222922    sGetDefender:
    29232923      if (Subject >= 0) and (Subject < MapSize) and (Occupant[Subject] = Player)
    29242924      then
    2925         Strongest(Subject, integer(Data), d, i, j)
    2926       else
    2927         result := eInvalid;
     2925        Strongest(Subject, Integer(Data), D, I, J)
     2926      else
     2927        Result := eInvalid;
    29282928
    29292929    sGetBattleForecast, sGetBattleForecastEx:
     
    29352935            ((pAtt = Player) or (RWemix[Player, pAtt, mixAtt] >= 0)) then
    29362936          begin
    2937             result := GetBattleForecast(Subject, TBattleForecast(Data), uix1,
     2937            Result := GetBattleForecast(Subject, TBattleForecast(Data), uix1,
    29382938              cix1, AStr, DStr, ABaseDamage, DBaseDamage);
    29392939            if Command = sGetBattleForecastEx then
     
    29442944              TBattleForecastEx(Data).DBaseDamage := DBaseDamage;
    29452945            end;
    2946             if result = eOK then
    2947               result := eInvalid; // no enemy unit there!
     2946            if Result = eOK then
     2947              Result := eInvalid; // no enemy unit there!
    29482948          end
    29492949          else
    2950             result := eInvalid
    2951       else
    2952         result := eInvalid;
     2950            Result := eInvalid
     2951      else
     2952        Result := eInvalid;
    29532953
    29542954    sGetUnitReport:
    29552955      if (Subject < 0) or (Subject >= RW[Player].nUn) or
    29562956        (RW[Player].Un[Subject].Loc < 0) then
    2957         result := eInvalid
     2957        Result := eInvalid
    29582958      else
    29592959        GetUnitReport(Player, Subject, TUnitReport(Data));
     
    29622962      if (Subject < 0) or (Subject >= RW[Player].nUn) or
    29632963        (RW[Player].Un[Subject].Loc < 0) then
    2964         result := eInvalid
    2965       else
    2966         result := GetMoveAdvice(Player, Subject, TMoveAdviceData(Data));
     2964        Result := eInvalid
     2965      else
     2966        Result := GetMoveAdvice(Player, Subject, TMoveAdviceData(Data));
    29672967
    29682968    sGetPlaneReturn:
     
    29702970        (RW[Player].Un[Subject].Loc < 0) or
    29712971        (RW[Player].Model[RW[Player].Un[Subject].mix].Domain <> dAir) then
    2972         result := eInvalid
     2972        Result := eInvalid
    29732973      else
    29742974      begin
    29752975        if CanPlaneReturn(Player, Subject, TPlaneReturnData(Data)) then
    2976           result := eOK
     2976          Result := eOK
    29772977        else
    2978           result := eNoWay;
     2978          Result := eNoWay;
    29792979      end;
    29802980
     
    29872987          Owner := Player;
    29882988          SearchCity(Subject, Owner, cix1);
    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);
     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);
    29922992        end
    29932993      else
    2994         result := eInvalid;
     2994        Result := eInvalid;
    29952995
    29962996    sGetCityReport:
    29972997      if (Subject < 0) or (Subject >= RW[Player].nCity) or
    29982998        (RW[Player].City[Subject].Loc < 0) then
    2999         result := eInvalid
    3000       else
    3001         result := GetCityReport(Player, Subject, TCityReport(Data));
     2999        Result := eInvalid
     3000      else
     3001        Result := GetCityReport(Player, Subject, TCityReport(Data));
    30023002
    30033003    sGetCityReportNew:
    30043004      if (Subject < 0) or (Subject >= RW[Player].nCity) or
    30053005        (RW[Player].City[Subject].Loc < 0) then
    3006         result := eInvalid
     3006        Result := eInvalid
    30073007      else
    30083008        GetCityReportNew(Player, Subject, TCityReportNew(Data));
     
    30113011      if (Subject < 0) or (Subject >= RW[Player].nCity) or
    30123012        (RW[Player].City[Subject].Loc < 0) then
    3013         result := eInvalid
     3013        Result := eInvalid
    30143014      else
    30153015        GetCityAreaInfo(Player, RW[Player].City[Subject].Loc,
     
    30313031      end
    30323032      else
    3033         result := eInvalid;
     3033        Result := eInvalid;
    30343034
    30353035    sGetEnemyCityReportNew:
     
    30483048      end
    30493049      else
    3050         result := eInvalid;
     3050        Result := eInvalid;
    30513051
    30523052    sGetEnemyCityAreaInfo:
     
    30623062      end
    30633063      else
    3064         result := eInvalid;
     3064        Result := eInvalid;
    30653065
    30663066    sGetCityTileAdvice:
    30673067      if (Subject < 0) or (Subject >= RW[Player].nCity) or
    30683068        (RW[Player].City[Subject].Loc < 0) then
    3069         result := eInvalid
     3069        Result := eInvalid
    30703070      else
    30713071        GetCityTileAdvice(Player, Subject, TCityTileAdviceData(Data));
     
    30803080          EditTile(Loc, NewTile)
    30813081      else
    3082         result := eInvalid;
     3082        Result := eInvalid;
    30833083
    30843084    sRandomMap:
     
    30863086      begin
    30873087        CreateElevation;
    3088         PreviewElevation := false;
    3089         CreateMap(false);
     3088        PreviewElevation := False;
     3089        CreateMap(False);
    30903090        FillChar(ObserveLevel, MapSize * 4, 0);
    30913091        DiscoverAll(Player, lObserveSuper);
    30923092      end
    30933093      else
    3094         result := eInvalid;
     3094        Result := eInvalid;
    30953095
    30963096    sMapGeneratorRequest:
    30973097      if not MapGeneratorAvailable then
    3098         result := eInvalid;
     3098        Result := eInvalid;
    30993099
    31003100    {
     
    31043104    sTurn, sTurn - sExecute:
    31053105      begin
    3106         AllHumansDead := true;
     3106        AllHumansDead := True;
    31073107        for p1 := 0 to nPl - 1 do
    31083108          if (1 shl p1 and GAlive <> 0) and (bix[p1].Kind = btTerm) then
    3109             AllHumansDead := false;
     3109            AllHumansDead := False;
    31103110        if (pDipActive >= 0) // still in negotiation mode
    31113111          or (pTurn = 0) and ((GWinner > 0) or (GTurn = MaxTurn) or
    31123112          (Difficulty[0] > 0) and AllHumansDead) then // game end reached
    3113           result := eViolation
     3113          Result := eViolation
    31143114        else if Command >= sExecute then
    31153115        begin
     
    31223122            begin
    31233123              LogChanges;
    3124               SaveGame('~' + LogFileName, true);
     3124              SaveGame('~' + LogFileName, True);
    31253125            end;
    31263126{$ENDIF}
     
    31373137            TotalFood := 0;
    31383138            TotalProd := 0;
    3139             for i := 0 to RW[pTurn].nCity - 1 do
    3140               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
    31413141              begin
    3142                 inc(TotalFood, RW[pTurn].City[i].Food);
    3143                 inc(TotalProd, RW[pTurn].City[i].Prod);
     3142                Inc(TotalFood, RW[pTurn].City[I].Food);
     3143                Inc(TotalProd, RW[pTurn].City[I].Prod);
    31443144              end;
    31453145            CheckSum := TotalFood and 7 + TotalProd and 7 shl 3 +
     
    31523152          begin
    31533153            if CheckSum <> Subject then
    3154               LoadOK := false;
     3154              LoadOK := False;
    31553155          end
    31563156          else // save checksum
     
    31793179            pTurn := (pTurn + 1) mod nPl;
    31803180            if pTurn = 0 then
    3181               inc(GTurn);
     3181              Inc(GTurn);
    31823182            if Assigned(bix[pTurn]) and ((1 shl pTurn) and GAlive = 0) then
    31833183            begin // already made extinct -- continue statistics
     
    32183218    sBreak, sResign, sNextRound, sReload:
    32193219      if Mode = moMovie then
    3220         MovieStopped := true
     3220        MovieStopped := True
    32213221      else
    32223222      begin
     
    32243224        begin
    32253225          ok := (Difficulty[0] = 0) and (bix[0].Kind <> btNoTerm) and
    3226             (integer(Data) >= 0) and (integer(Data) < GTurn);
     3226            (Integer(Data) >= 0) and (Integer(Data) < GTurn);
    32273227          for p1 := 1 to nPl - 1 do
    32283228            if bix[p1].Kind = btTerm then
    3229               ok := false;
     3229              ok := False;
    32303230          // allow reload in AI-only games only
    32313231        end
     
    32363236          if (Command = sBreak) or (Command = sResign) then
    32373237            Notify(ntBackOn);
    3238           for i := 0 to Brains.Count - 1 do
    3239             if Brains[i].Initialized then
     3238          for I := 0 to Brains.Count - 1 do
     3239            if Brains[I].Initialized then
    32403240            begin
    3241               if Brains[i].Kind = btAI then
    3242                 Notify(ntDeinitModule, i);
    3243               CallClient(i, cBreakGame, nil^);
     3241              if Brains[I].Kind = btAI then
     3242                Notify(ntDeinitModule, I);
     3243              CallClient(I, cBreakGame, nil^);
    32443244            end;
    32453245          Notify(ntEndInfo);
     
    32483248            LogCityTileChanges;
    32493249            LogChanges;
    3250             SaveGame(LogFileName, false);
     3250            SaveGame(LogFileName, False);
    32513251          end;
    32523252          DeleteFile(SavePath + '~' + LogFileName);
     
    32613261                LandMass, MaxTurn);
    32623262            sReload:
    3263               LoadGame(SavePath, LogFileName, integer(Data), false);
     3263              LoadGame(SavePath, LogFileName, Integer(Data), False);
    32643264          end;
    32653265        end
    32663266        else
    3267           result := eInvalid;
     3267          Result := eInvalid;
    32683268      end;
    32693269
     
    32823282      end
    32833283      else
    3284         result := eInvalid;
     3284        Result := eInvalid;
    32853285
    32863286    scContact .. scContact + (nPl - 1) shl 4, scContact - sExecute .. scContact
    32873287      - sExecute + (nPl - 1) shl 4:
    32883288      if (pDipActive >= 0) or (1 shl (Command shr 4 and $F) and GAlive = 0) then
    3289         result := eInvalid
     3289        Result := eInvalid
    32903290      else if GWinner > 0 then
    3291         result := eViolation // game end reached
     3291        Result := eViolation // game end reached
    32923292      else if RW[Player].Treaty[Command shr 4 and $F] = trNoContact then
    3293         result := eNoPreq
     3293        Result := eNoPreq
    32943294      else if GTurn < GColdWarStart + ColdWarTurns then
    3295         result := eColdWar
     3295        Result := eColdWar
    32963296      else if RW[Player].Government = gAnarchy then
    3297         result := eAnarchy
     3297        Result := eAnarchy
    32983298      else if RW[Command shr 4 and $F].Government = gAnarchy then
    32993299      begin
    3300         result := eAnarchy;
     3300        Result := eAnarchy;
    33013301        LastEndClientCommand := scReject; // enable cancel treaty
    33023302        pContacted := Command shr 4 and $F;
     
    33063306        pContacted := Command shr 4 and $F;
    33073307        pDipActive := pContacted;
    3308         assert(Mode = moPlaying);
     3308        Assert(Mode = moPlaying);
    33093309        Inform(pDipActive);
    33103310        ChangeClientWhenDone(scContact, pDipActive, pTurn, 4);
     
    33173317        begin // contact requested and not accepted yet
    33183318          pDipActive := -1;
    3319           assert(Mode = moPlaying);
     3319          Assert(Mode = moPlaying);
    33203320          ChangeClientWhenDone(cContinue, pTurn, nil^, 0);
    33213321        end;
    33223322      end
    33233323      else
    3324         result := eInvalid;
     3324        Result := eInvalid;
    33253325
    33263326    scDipStart, scDipStart - sExecute:
     
    33333333            RW[pTurn].Credibility;
    33343334          pDipActive := pTurn;
    3335           assert(Mode = moPlaying);
     3335          Assert(Mode = moPlaying);
    33363336          IntServer(sIntHaveContact, pTurn, pContacted, nil^);
    33373337          ChangeClientWhenDone(scDipStart, pDipActive, nil^, 0);
     
    33393339      end
    33403340      else
    3341         result := eInvalid;
     3341        Result := eInvalid;
    33423342
    33433343    scDipNotice, scDipAccept, scDipCancelTreaty, scDipBreak,
     
    33463346      if pDipActive >= 0 then
    33473347      begin
    3348         assert(Mode = moPlaying);
     3348        Assert(Mode = moPlaying);
    33493349        if pDipActive = pTurn then
    33503350          p1 := pContacted
     
    33623362            // check if offer can be accepted
    33633363            if nDeliver + nCost = 0 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
     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
    33723372            begin
    33733373              IntServer(sIntPayPrices + nDeliver + nCost, p1, pDipActive,
     
    33763376
    33773377              // tell other players about ship part trades
    3378               HasShipChanged := false;
     3378              HasShipChanged := False;
    33793379              FillChar(ShowShipChange, SizeOf(ShowShipChange), 0);
    3380               for i := 0 to nDeliver + nCost - 1 do
    3381                 if Price[i] and opMask = opShipParts then
     3380              for I := 0 to nDeliver + nCost - 1 do
     3381                if Price[I] and opMask = opShipParts then
    33823382                begin
    3383                   HasShipChanged := true;
    3384                   if i >= nDeliver then
     3383                  HasShipChanged := True;
     3384                  if I >= nDeliver then
    33853385                  begin // p1 has demanded from pDipActive
    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);
     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);
    33903390                  end
    33913391                  else
    33923392                  begin // p1 has delivered to pDipActive
    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);
     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);
    33973397                  end;
    33983398                end;
     
    34063406                    (1 shl p2 and (GAlive or GWatching) <> 0) then
    34073407                  begin
    3408                     move(GShip, RW[p2].Ship, SizeOf(GShip));
     3408                    Move(GShip, RW[p2].Ship, SizeOf(GShip));
    34093409                    if 1 shl p2 and GWatching <> 0 then
    34103410                      CallPlayer(cShowShipChange, p2, ShowShipChange);
     
    34193419            (GTurn < RW[pDipActive].LastCancelTreaty[p1] + CancelTreatyTurns)
    34203420          then
    3421             result := eCancelTreatyRush
     3421            Result := eCancelTreatyRush
    34223422          else if Command >= sExecute then
    34233423          begin
     
    34263426              if (p2 <> p1) and (1 shl p2 and PeaceEnded <> 0) then
    34273427              begin
    3428                 i := p1 shl 4 + pDipActive;
    3429                 CallPlayer(cShowSupportAllianceAgainst, p2, i);
     3428                I := p1 shl 4 + pDipActive;
     3429                CallPlayer(cShowSupportAllianceAgainst, p2, I);
    34303430              end;
    34313431            for p2 := 0 to nPl - 1 do
    34323432              if (p2 <> p1) and (1 shl p2 and PeaceEnded <> 0) then
    34333433              begin
    3434                 i := p2;
    3435                 CallPlayer(cShowCancelTreatyByAlliance, pDipActive, i);
     3434                I := p2;
     3435                CallPlayer(cShowCancelTreatyByAlliance, pDipActive, I);
    34363436              end;
    34373437          end;
    34383438        end
    34393439        else
    3440           result := eInvalid;
    3441         if (Command >= sExecute) and (result >= rExecuted) then
     3440          Result := eInvalid;
     3441        if (Command >= sExecute) and (Result >= rExecuted) then
    34423442          if LastEndClientCommand = scDipBreak then
    34433443          begin // break negotiation
     
    34613461      end
    34623462      else
    3463         result := eInvalid;
     3463        Result := eInvalid;
    34643464
    34653465    scDipOffer, scDipOffer - sExecute:
     
    34743474            pDipActive := -1;
    34753475            CallPlayer(cShowEndContact, pContacted, nil^);
    3476             assert(Mode = moPlaying);
     3476            Assert(Mode = moPlaying);
    34773477            ChangeClientWhenDone(cContinue, pTurn, nil^, 0);
    34783478          end;
     
    34873487          if RW[pDipActive].Treaty[p1] < trPeace then
    34883488          begin // no tribute allowed!
    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;
     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;
    34953495          end;
    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;
     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;
    35003500          if CountPrice(TOffer(Data), opTreaty) > 1 then
    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;
     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;
    35053505          if CountPrice(TOffer(Data), opMoney) > 1 then
    3506             result := eInvalidOffer;
     3506            Result := eInvalidOffer;
    35073507          if CountPrice(TOffer(Data), opTribute) > 1 then
    3508             result := eInvalidOffer;
     3508            Result := eInvalidOffer;
    35093509          case CountPrice(TOffer(Data), opChoose) of
    35103510            0:
     
    35123512            1:
    35133513              if (TOffer(Data).nCost = 0) or (TOffer(Data).nDeliver = 0) then
    3514                 result := eInvalidOffer;
     3514                Result := eInvalidOffer;
    35153515          else
    3516             result := eInvalidOffer;
     3516            Result := eInvalidOffer;
    35173517          end;
    35183518
    35193519          // !!! check here if cost can be demanded
    35203520
    3521           if (Command >= sExecute) and (result >= rExecuted) then
     3521          if (Command >= sExecute) and (Result >= rExecuted) then
    35223522          begin
    35233523            OfferFullySupported := (TOffer(Data).nDeliver <= 2) and
    35243524              (TOffer(Data).nCost <= 2); // >2 no more allowed
    3525             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
    35263526            begin
    3527               if TOffer(Data).Price[i] and opMask = opTribute then
    3528                 OfferFullySupported := false;
     3527              if TOffer(Data).Price[I] and opMask = opTribute then
     3528                OfferFullySupported := False;
    35293529              // tribute no more part of the game
    3530               if (TOffer(Data).Price[i] and opMask = opTreaty) and
    3531                 (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])
    35323532              then
    3533                 OfferFullySupported := false;
     3533                OfferFullySupported := False;
    35343534              // agreed treaty end no more part of the game
    3535               if TOffer(Data).Price[i] = opTreaty + trCeaseFire then
    3536                 OfferFullySupported := false;
     3535              if TOffer(Data).Price[I] = opTreaty + trCeaseFire then
     3536                OfferFullySupported := False;
    35373537              // ceasefire no more part of the game
    35383538            end;
     
    35593559              LastOffer := TOffer(Data);
    35603560              // show offered things to receiver
    3561               for i := 0 to LastOffer.nDeliver - 1 do
    3562                 ShowPrice(pDipActive, p1, LastOffer.Price[i]);
     3561              for I := 0 to LastOffer.nDeliver - 1 do
     3562                ShowPrice(pDipActive, p1, LastOffer.Price[I]);
    35633563              pDipActive := p1;
    3564               assert(Mode = moPlaying);
     3564              Assert(Mode = moPlaying);
    35653565              ChangeClientWhenDone(scDipOffer, pDipActive, LastOffer,
    35663566                SizeOf(LastOffer));
     
    35693569        end
    35703570      else
    3571         result := eInvalid;
     3571        Result := eInvalid;
    35723572
    35733573    {
     
    35823582      end
    35833583      else
    3584         result := eInvalid;
     3584        Result := eInvalid;
    35853585
    35863586    sSetTestFlag:
     
    35923592      end
    35933593      else
    3594         result := eInvalid;
     3594        Result := eInvalid;
    35953595
    35963596    sSetGovernment, sSetGovernment - sExecute:
     
    35983598{$IFDEF TEXTLOG}CmdInfo := Format('SetGovernment P%d: %d', [Player, Subject]); {$ENDIF}
    35993599        if RW[Player].Happened and phChangeGov = 0 then
    3600           result := eViolation
     3600          Result := eViolation
    36013601        else if RW[Player].Government = Subject then
    3602           result := eNotChanged
     3602          Result := eNotChanged
    36033603        else if (Subject >= nGov) then
    3604           result := eInvalid
     3604          Result := eInvalid
    36053605        else if (Subject >= gMonarchy) and
    36063606          (RW[Player].Tech[GovPreq[Subject]] < tsApplicable) then
    3607           result := eNoPreq
     3607          Result := eNoPreq
    36083608        else if Command >= sExecute then
    36093609        begin
     
    36203620{$IFDEF TEXTLOG}CmdInfo := Format('SetRates P%d: %d/%d', [Player, Subject and $F * 10, Subject shr 4 * 10]); {$ENDIF}
    36213621        if Subject and $F + Subject shr 4 > 10 then
    3622           result := eInvalid
     3622          Result := eInvalid
    36233623        else if (RW[Player].TaxRate = Subject and $F * 10) and
    36243624          (RW[Player].LuxRate = Subject shr 4 * 10) then
    3625           result := eNotChanged
     3625          Result := eNotChanged
    36263626        else if Command >= sExecute then
    36273627        begin
     
    36353635{$IFDEF TEXTLOG}CmdInfo := Format('Revolution P%d', [Player]); {$ENDIF}
    36363636        if RW[Player].Government = gAnarchy then
    3637           result := eInvalid
     3637          Result := eInvalid
    36383638        else
    36393639        begin
     
    36573657          if (Mode = moPlaying) and (Subject = adMilitary) and
    36583658            (DevModelTurn[Player] <> GTurn) then
    3659             result := eNoModel
     3659            Result := eNoModel
    36603660          else if Subject <> adMilitary then
    36613661          begin
     
    36633663            begin
    36643664              if Tech[Subject] >= MaxFutureTech_Computing then
    3665                 result := eInvalid;
     3665                Result := eInvalid;
    36663666            end
    36673667            else if Subject in FutureTech then
    36683668            begin
    36693669              if Tech[Subject] >= MaxFutureTech then
    3670                 result := eInvalid;
     3670                Result := eInvalid;
    36713671            end
    36723672            else if Tech[Subject] >= tsApplicable then
    3673               result := eInvalid; // already discovered
     3673              Result := eInvalid; // already discovered
    36743674            if Tech[Subject] <> tsSeen then // look if preqs met
    36753675              if AdvPreq[Subject, 2] <> preNone then
    36763676              begin // 2 of 3 required
    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;
     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;
    36833683              end
    36843684              else if (AdvPreq[Subject, 0] <> preNone) and
     
    36863686                (AdvPreq[Subject, 1] <> preNone) and
    36873687                (Tech[AdvPreq[Subject, 1]] < tsApplicable) then
    3688                 result := eNoPreq;
     3688                Result := eNoPreq;
    36893689          end;
    3690           if (result = eOK) and (Command >= sExecute) then
     3690          if (Result = eOK) and (Command >= sExecute) then
    36913691          begin
    36923692            if (Mode = moPlaying) and (Subject = adMilitary) then
     
    36973697        end
    36983698        else
    3699           result := eViolation;
     3699          Result := eViolation;
    37003700      end;
    37013701
     
    37053705        {$ENDIF}
    37063706        if RW[Player].Happened and phStealTech = 0 then
    3707           result := eInvalid
     3707          Result := eInvalid
    37083708        else if (Subject >= nAdv) or (Subject in FutureTech) or
    37093709          (RW[Player].Tech[Subject] >= tsSeen) or
    37103710          (RW[GStealFrom].Tech[Subject] < tsApplicable) then
    3711           result := eInvalid
     3711          Result := eInvalid
    37123712        else if Command >= sExecute then
    37133713        begin
    37143714          SeeTech(Player, Subject);
    3715           dec(RW[Player].Happened, phStealTech);
     3715          Dec(RW[Player].Happened, phStealTech);
    37163716        end;
    37173717      end;
     
    37243724        if (Subject >= nAttitude) or (p1 >= nPl) or
    37253725          (RW[Player].EnemyReport[p1] = nil) then
    3726           result := eInvalid
     3726          Result := eInvalid
    37273727        else if RW[Player].Treaty[p1] = trNoContact then
    3728           result := eNoPreq
     3728          Result := eNoPreq
    37293729        else if RW[Player].Attitude[p1] = Subject then
    3730           result := eNotChanged
     3730          Result := eNotChanged
    37313731        else if Command >= sExecute then
    37323732        begin
     
    37393739      if (LastEndClientCommand <> scReject) or
    37403740        (RW[Player].Treaty[pContacted] < trPeace) then
    3741         result := eInvalid
     3741        Result := eInvalid
    37423742      else if (ServerVersion[Player] >= $010100) and
    37433743        (GTurn < RW[Player].LastCancelTreaty[pContacted] + CancelTreatyTurns)
    37443744      then
    3745         result := eCancelTreatyRush
     3745        Result := eCancelTreatyRush
    37463746      else if Command >= sExecute then
    37473747      begin
     
    37513751          if (p2 <> pContacted) and (1 shl p2 and PeaceEnded <> 0) then
    37523752          begin
    3753             i := pContacted shl 4 + Player;
    3754             CallPlayer(cShowSupportAllianceAgainst, p2, i);
     3753            I := pContacted shl 4 + Player;
     3754            CallPlayer(cShowSupportAllianceAgainst, p2, I);
    37553755          end;
    37563756        for p2 := 0 to nPl - 1 do
    37573757          if (p2 <> pContacted) and (1 shl p2 and PeaceEnded <> 0) then
    37583758          begin
    3759             i := p2;
    3760             CallPlayer(cShowCancelTreatyByAlliance, Player, i);
     3759            I := p2;
     3760            CallPlayer(cShowCancelTreatyByAlliance, Player, I);
    37613761          end;
    37623762        LastEndClientCommand := sTurn;
     
    37713771{$IFDEF TEXTLOG}CmdInfo := Format('CreateDevModel P%d', [Player]); {$ENDIF}
    37723772        if Subject >= 4 then
    3773           result := eInvalid
     3773          Result := eInvalid
    37743774        else if (upgrade[Subject, 0].Preq <> preNone) and
    37753775          (RW[Player].Tech[upgrade[Subject, 0].Preq] < tsApplicable) then
    3776           result := eNoPreq
     3776          Result := eNoPreq
    37773777        else if Command >= sExecute then
    37783778        begin
     
    37853785            Upgrades := 0;
    37863786            FutureMCost := 0;
    3787             for i := 0 to nUpgrade - 1 do
    3788               with upgrade[Domain, i] do
     3787            for I := 0 to nUpgrade - 1 do
     3788              with upgrade[Domain, I] do
    37893789                if (Preq = preNone) or (Preq >= 0) and
    37903790                  ((RW[Player].Tech[Preq] >= tsApplicable) or
     
    37933793                  if Preq in FutureTech then
    37943794                  begin
    3795                     j := RW[Player].Tech[Preq];
    3796                     inc(FutureMCost, j * Cost);
     3795                    J := RW[Player].Tech[Preq];
     3796                    Inc(FutureMCost, J * Cost);
    37973797                  end
    37983798                  else
    37993799                  begin
    3800                     j := 1;
     3800                    J := 1;
    38013801                    if Cost > MCost then
    38023802                      MCost := Cost;
    38033803                  end;
    3804                   inc(Upgrades, 1 shl i);
    3805                   inc(MStrength, j * Strength);
    3806                   inc(MTrans, j * Trans);
     3804                  Inc(Upgrades, 1 shl I);
     3805                  Inc(MStrength, J * Strength);
     3806                  Inc(MTrans, J * Trans);
    38073807                end;
    3808             inc(MCost, FutureMCost);
     3808            Inc(MCost, FutureMCost);
    38093809            FillChar(Cap, SizeOf(Cap), 0);
    38103810            Cap[mcOffense] := 2;
    38113811            Cap[mcDefense] := 1;
    3812             for i := 0 to nFeature - 1 do
    3813               with Feature[i] do
     3812            for I := 0 to nFeature - 1 do
     3813              with Feature[I] do
    38143814                if (1 shl Domain and Domains <> 0) and
    38153815                  ((Preq = preNone) or (Preq = preSun) and
    38163816                  (GWonder[woSun].EffectiveOwner = Player) or (Preq >= 0) and
    3817                   (RW[Player].Tech[Preq] >= tsApplicable)) and (i in AutoFeature)
     3817                  (RW[Player].Tech[Preq] >= tsApplicable)) and (I in AutoFeature)
    38183818                then
    3819                   Cap[i] := 1;
     3819                  Cap[I] := 1;
    38203820            MaxWeight := 5;
    38213821            if (WeightPreq7[Domain] <> preNA) and
     
    38393839{$IFDEF TEXTLOG}CmdInfo := Format('SetDevModelCap P%d', [Player]); {$ENDIF}
    38403840        if Subject >= nFeature then
    3841           result := eInvalid
     3841          Result := eInvalid
    38423842        else if DevModelTurn[Player] = GTurn then
    38433843        begin
     
    38453845          with RW[Player].DevModel do
    38463846            if 1 shl Domain and Feature[Subject].Domains = 0 then
    3847               result := eDomainMismatch
     3847              Result := eDomainMismatch
    38483848            else if not((Feature[Subject].Preq = preNone) or
    38493849              (Feature[Subject].Preq = preSun) and
     
    38513851              (Feature[Subject].Preq >= 0) and
    38523852              (RW[Player].Tech[Feature[Subject].Preq] >= tsApplicable)) then
    3853               result := eNoPreq
     3853              Result := eNoPreq
    38543854            else
    38553855            begin
     
    38673867                  MaxCap := 3;
    38683868                if RW[Player].Tech[adSteel] >= tsApplicable then
    3869                   inc(MaxCap);
     3869                  Inc(MaxCap);
    38703870              end
    38713871              else
     
    38773877              if (NewCap < MinCap) or (NewCap > MaxCap) or
    38783878                (Weight + (NewCap - Cap[Subject]) * CapWeight > MaxWeight) then
    3879                 result := eViolation
     3879                Result := eViolation
    38803880              else if Command >= sExecute then
    38813881              begin
     
    39203920        end
    39213921        else
    3922           result := eNoModel;
     3922          Result := eNoModel;
    39233923      end;
    39243924
     
    39313931{$IFDEF TEXTLOG}CmdInfo := Format('RemoveUnit P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF}
    39323932        if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then
    3933           result := eInvalid
     3933          Result := eInvalid
    39343934        else
    39353935        begin
    3936           result := eRemoved;
     3936          Result := eRemoved;
    39373937          Loc0 := RW[Player].Un[Subject].Loc;
    39383938          if RealMap[Loc0] and fCity <> 0 then { check utilize }
     
    39463946                (Project and cpImp = 0) and
    39473947                (RW[Player].Model[Project and cpIndex].Kind <> mkCaravan) then
    3948                 result := eUtilized;
     3948                Result := eUtilized;
    39493949              if Command >= sExecute then
    39503950              begin
    3951                 if result = eUtilized then
     3951                if Result = eUtilized then
    39523952                begin
    39533953                  with RW[Player].Un[Subject] do
    39543954                  begin
    3955                     Cost := integer(RW[Player].Model[mix].Cost) * Health *
     3955                    Cost := Integer(RW[Player].Model[mix].Cost) * Health *
    39563956                      BuildCostMod[Difficulty[Player]] div 1200;
    39573957                    if RW[Player].Model[mix].Cap[mcLine] > 0 then
     
    39593959                  end;
    39603960                  if Project and (cpImp + cpIndex) = cpImp + imTrGoods then
    3961                     inc(RW[Player].Money, Cost)
     3961                    Inc(RW[Player].Money, Cost)
    39623962                  else
    39633963                  begin
    3964                     inc(Prod, Cost * 2 div 3);
     3964                    Inc(Prod, Cost * 2 div 3);
    39653965                    Project0 := Project0 and not cpCompleted;
    39663966                    if Project0 and not cpAuto <> Project and not cpAuto then
     
    39823982{$IFDEF TEXTLOG}CmdInfo := Format('SetUnitHome P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF}
    39833983        if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then
    3984           result := eInvalid
     3984          Result := eInvalid
    39853985        else
    39863986        begin
    39873987          Loc0 := RW[Player].Un[Subject].Loc;
    39883988          if RealMap[Loc0] and fCity = 0 then
    3989             result := eInvalid
     3989            Result := eInvalid
    39903990          else
    39913991          begin
    39923992            SearchCity(Loc0, Player, cix1);
    39933993            if RW[Player].City[cix1].Flags and chCaptured <> 0 then
    3994               result := eViolation
     3994              Result := eViolation
    39953995            else if Command >= sExecute then
    39963996              RW[Player].Un[Subject].Home := cix1;
     
    40094009{$IFDEF TEXTLOG}CmdInfo := Format('LoadUnit P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF}
    40104010        if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then
    4011           result := eInvalid
     4011          Result := eInvalid
    40124012        else
    4013           result := LoadUnit(Player, Subject, Command < sExecute);
     4013          Result := LoadUnit(Player, Subject, Command < sExecute);
    40144014      end;
    40154015
     
    40184018{$IFDEF TEXTLOG}CmdInfo := Format('UnloadUnit P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF}
    40194019        if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then
    4020           result := eInvalid
     4020          Result := eInvalid
    40214021        else
    4022           result := UnloadUnit(Player, Subject, Command < sExecute);
     4022          Result := UnloadUnit(Player, Subject, Command < sExecute);
    40234023      end;
    40244024
    40254025    sSelectTransport, sSelectTransport - sExecute:
    40264026      if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then
    4027         result := eInvalid
     4027        Result := eInvalid
    40284028      else
    40294029        with RW[Player].Model[RW[Player].Un[Subject].mix] do
    40304030        begin
    40314031          if Cap[mcSeaTrans] + Cap[mcAirTrans] + Cap[mcCarrier] = 0 then
    4032             result := eInvalid
     4032            Result := eInvalid
    40334033          else if Command >= sExecute then
    40344034            uixSelectedTransport := Subject;
     
    40414041      begin
    40424042        p1 := Command shr 4 and $F;
    4043         Loc1 := integer(Data);
     4043        Loc1 := Integer(Data);
    40444044        if (Occupant[Loc1] >= 0) and (p1 <> Occupant[Loc1]) or
    40454045          (RealMap[Loc1] and fCity <> 0) and
    40464046          (RealMap[Loc1] shr 27 <> Cardinal(p1)) or
    40474047          (RW[p1].Model[Subject].Domain < dAir) and
    4048           ((RW[p1].Model[Subject].Domain = dSea) <> (RealMap[integer(Data)] and
     4048          ((RW[p1].Model[Subject].Domain = dSea) <> (RealMap[Integer(Data)] and
    40494049          fTerrain < fGrass)) then
    4050           result := eViolation
     4050          Result := eViolation
    40514051        else if Command >= sExecute then
    40524052        begin
    40534053          CreateUnit(p1, Subject);
    4054           RW[p1].Un[RW[p1].nUn - 1].Loc := integer(Data);
     4054          RW[p1].Un[RW[p1].nUn - 1].Loc := Integer(Data);
    40554055          PlaceUnit(p1, RW[p1].nUn - 1);
    4056           UpdateUnitMap(integer(Data));
     4056          UpdateUnitMap(Integer(Data));
    40574057        end;
    40584058      end
    40594059      else
    4060         result := eInvalid;
     4060        Result := eInvalid;
    40614061
    40624062    sMoveUnit + (0 + 6 * 8) * 16, sMoveUnit + (1 + 7 * 8) * 16,
     
    40754075{$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}
    40764076        if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then
    4077           result := eInvalid
     4077          Result := eInvalid
    40784078        else
    4079           result := MoveUnit(Player, Subject, dx, dy, Command < sExecute);
     4079          Result := MoveUnit(Player, Subject, dx, dy, Command < sExecute);
    40804080      end;
    40814081
     
    40884088{$IFDEF TEXTLOG}CmdInfo := Format('AddToCity P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF}
    40894089        if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then
    4090           result := eInvalid
     4090          Result := eInvalid
    40914091        else if not(RW[Player].Model[RW[Player].Un[Subject].mix].Kind
    40924092          in [mkSettler, mkSlaves]) and
    40934093          (RW[Player].Un[Subject].Flags and unConscripts = 0) then
    4094           result := eViolation
     4094          Result := eViolation
    40954095        else
    40964096        begin
    40974097          Loc0 := RW[Player].Un[Subject].Loc;
    40984098          if RealMap[Loc0] and fCity = 0 then
    4099             result := eInvalid
     4099            Result := eInvalid
    41004100          else
    41014101          begin
     
    41034103            with RW[Player].City[cix1] do
    41044104              if not CanCityGrow(Player, cix1) then
    4105                 result := eMaxSize
     4105                Result := eMaxSize
    41064106              else if Command >= sExecute then
    41074107              begin { add to city }
     
    41234123      begin
    41244124        Loc0 := RW[Player].Un[Subject].Loc;
    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}
     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}
    41274127        if (Subject >= RW[Player].nUn) or (Loc0 < 0) then
    4128           result := eInvalid
    4129         else if i >= nJob then
    4130           result := eInvalid
     4128          Result := eInvalid
     4129        else if I >= nJob then
     4130          Result := eInvalid
    41314131        else
    41324132        begin
    4133           result := StartJob(Player, Subject, i, Command < sExecute);
    4134           if result = eCity then
     4133          Result := StartJob(Player, Subject, I, Command < sExecute);
     4134          if Result = eCity then
    41354135          begin // new city
    41364136            cix1 := RW[Player].nCity - 1;
     
    41574157    sSetCityProject, sSetCityProject - sExecute:
    41584158      begin
    4159         NewProject := integer(Data) and not cpAuto;
     4159        NewProject := Integer(Data) and not cpAuto;
    41604160{$IFDEF TEXTLOG}CmdInfo := Format('SetCityProject P%d Loc%d: %d', [Player, RW[Player].City[Subject].Loc, NewProject]); {$ENDIF}
    41614161        if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0)
    41624162        then
    4163           result := eInvalid
     4163          Result := eInvalid
    41644164        else
    41654165          with RW[Player].City[Subject] do
    41664166          begin
    41674167            if NewProject = Project then
    4168               result := eNotChanged
     4168              Result := eNotChanged
    41694169            else
    41704170            begin
     
    41744174              begin
    41754175                if NewProject and cpIndex >= RW[Player].nModel then
    4176                   result := eInvalid
     4176                  Result := eInvalid
    41774177                else if (NewProject and cpConscripts <> 0) and
    41784178                  not((RW[Player].Tech[adConscription] >= tsApplicable) and
     
    41804180                  and (RW[Player].Model[NewProject and cpIndex].Kind < mkScout))
    41814181                then
    4182                   result := eViolation
     4182                  Result := eViolation
    41834183                  // else if (RW[Player].Model[NewProject and cpIndex].Kind=mkSlaves)
    41844184                  // and (GWonder[woPyramids].EffectiveOwner<>Player) then
     
    41864186              end
    41874187              else if NewProject and cpIndex >= nImp then
    4188                 result := eInvalid
     4188                Result := eInvalid
    41894189              else
    41904190              begin
    41914191                Preq := Imp[NewProject and cpIndex].Preq;
    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
     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
    41974197                else if Preq = preNA then
    4198                   result := eInvalid
     4198                  Result := eInvalid
    41994199                else if (Preq >= 0) and (RW[Player].Tech[Preq] < tsApplicable)
    42004200                then
    4201                   result := eNoPreq
     4201                  Result := eNoPreq
    42024202                else if built[NewProject and cpIndex] > 0 then
    4203                   result := eInvalid
     4203                  Result := eInvalid
    42044204                else if (NewProject and cpIndex < nWonder) and
    42054205                  (GWonder[NewProject and cpIndex].CityID <> WonderNotBuiltYet) then
    4206                   result := eViolation // wonder already exists
     4206                  Result := eViolation // wonder already exists
    42074207                else if (NewProject and cpIndex = imSpacePort) and
    42084208                  (RW[Player].NatBuilt[imSpacePort] > 0) then
    4209                   result := eViolation // space port already exists
     4209                  Result := eViolation // space port already exists
    42104210                else if (NewProject = cpImp + imBank) and (built[imMarket] = 0)
    42114211                  or (NewProject = cpImp + imUniversity) and
     
    42134213                  (built[imUniversity] = 0) or (NewProject = cpImp + imMfgPlant)
    42144214                  and (built[imFactory] = 0) then
    4215                   result := eNoPreq;
     4215                  Result := eNoPreq;
    42164216                case NewProject - cpImp of
    42174217                  woLighthouse, woMagellan, imCoastalFort, imHarbor, imPlatform:
     
    42244224                        if (Loc1 >= 0) and (Loc1 < MapSize) and
    42254225                          (RealMap[Loc1] and fTerrain = fShore) then
    4226                           inc(Preq);
     4226                          Inc(Preq);
    42274227                      end;
    42284228                      if Preq = 0 then
    4229                         result := eNoPreq;
     4229                        Result := eNoPreq;
    42304230                    end;
    42314231                  woHoover, imHydro:
     
    42394239                          ((RealMap[Loc1] and fTerrain = fMountains) or
    42404240                          (RealMap[Loc1] and fRiver <> 0)) then
    4241                           inc(Preq);
     4241                          Inc(Preq);
    42424242                      end;
    42434243                      if Preq = 0 then
    4244                         result := eNoPreq;
     4244                        Result := eNoPreq;
    42454245                    end;
    42464246                  woMIR, imShipComp, imShipPow, imShipHab:
    42474247                    if RW[Player].NatBuilt[imSpacePort] = 0 then
    4248                       result := eNoPreq;
     4248                      Result := eNoPreq;
    42494249                end;
    42504250                if (GTestFlags and tfNoRareNeed = 0) and
    42514251                  (Imp[NewProject and cpIndex].Kind = ikShipPart) then
    42524252                  if RW[Player].Tech[adMassProduction] < tsApplicable then
    4253                     result := eNoPreq
     4253                    Result := eNoPreq
    42544254                  else
    42554255                  begin // check for rare resources
    42564256                    if NewProject and cpIndex = imShipComp then
    4257                       j := 1
     4257                      J := 1
    42584258                    else if NewProject and cpIndex = imShipPow then
    4259                       j := 2
     4259                      J := 2
    42604260                    else { if NewProject and cpIndex=imShipHab then }
    4261                       j := 3;
     4261                      J := 3;
    42624262                    // j = rare resource required
    42634263                    Preq := 0;
     
    42674267                      Loc1 := Radius[V21];
    42684268                      if (Loc1 >= 0) and (Loc1 < MapSize) and
    4269                         (RealMap[Loc1] shr 25 and 3 = Cardinal(j)) then
    4270                         inc(Preq);
     4269                        (RealMap[Loc1] shr 25 and 3 = Cardinal(J)) then
     4270                        Inc(Preq);
    42714271                    end;
    42724272                    if Preq = 0 then
    4273                       result := eNoPreq;
     4273                      Result := eNoPreq;
    42744274                  end;
    42754275              end;
    42764276
    4277               if (Command >= sExecute) and (result >= rExecuted) then
     4277              if (Command >= sExecute) and (Result >= rExecuted) then
    42784278              begin
    42794279                if pt0 <> ptSelect then
     
    42844284                    and (pt0 <> ptCaravan) then
    42854285                  begin
    4286                     inc(RW[Player].Money, Prod0);
     4286                    Inc(RW[Player].Money, Prod0);
    42874287                    Prod := 0;
    42884288                    Prod0 := 0;
     
    42914291                  else
    42924292                    Prod := Prod0 * 2 div 3;
    4293                 Project := NewProject
     4293                Project := NewProject;
    42944294              end;
    42954295            end;
     
    43024302        if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0)
    43034303        then
    4304           result := eInvalid
     4304          Result := eInvalid
    43054305        else
    43064306          with RW[Player].City[Subject] do
    43074307            if (RW[Player].Government = gAnarchy) or (Flags and chCaptured <> 0)
    43084308            then
    4309               result := eOutOfControl
     4309              Result := eOutOfControl
    43104310            else if (Project and cpImp <> 0) and
    43114311              ((Project and cpIndex = imTrGoods) or
    43124312              (Imp[Project and cpIndex].Kind = ikShipPart)) then
    4313               result := eInvalid // don't buy colony ship
     4313              Result := eInvalid // don't buy colony ship
    43144314            else
    43154315            begin
     
    43304330                Cost := Cost * 4;
    43314331              if Cost <= 0 then
    4332                 result := eNotChanged
     4332                Result := eNotChanged
    43334333              else if Cost > RW[Player].Money then
    4334                 result := eViolation
     4334                Result := eViolation
    43354335              else if Command >= sExecute then
    43364336                IntServer(sIntBuyMaterial, Player, Subject, Cost);
     
    43454345        if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0)
    43464346        then
    4347           result := eInvalid
     4347          Result := eInvalid
    43484348        else if Command >= sExecute then
    43494349          with RW[Player].City[Subject] do
    43504350          begin
    4351             inc(RW[Player].Money, Prod0);
     4351            Inc(RW[Player].Money, Prod0);
    43524352            Prod := 0;
    43534353            Prod0 := 0;
     
    43574357    sSellCityImprovement, sSellCityImprovement - sExecute:
    43584358      begin
    4359 {$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}
    43604360        if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0)
    43614361        then
    4362           result := eInvalid
     4362          Result := eInvalid
    43634363        else
    43644364          with RW[Player].City[Subject] do
    4365             if built[integer(Data)] = 0 then
    4366               result := eInvalid
     4365            if built[Integer(Data)] = 0 then
     4366              Result := eInvalid
    43674367            else if (RW[Player].Government = gAnarchy) or
    43684368              (Flags and chCaptured <> 0) then
    4369               result := eOutOfControl
     4369              Result := eOutOfControl
    43704370            else if Flags and chImprovementSold <> 0 then
    4371               result := eOnlyOnce
     4371              Result := eOnlyOnce
    43724372            else if Command >= sExecute then
    43734373            begin
    4374               inc(RW[Player].Money, Imp[integer(Data)].Cost * BuildCostMod
     4374              Inc(RW[Player].Money, Imp[Integer(Data)].Cost * BuildCostMod
    43754375                [Difficulty[Player]] div 12);
    4376               built[integer(Data)] := 0;
    4377               if Imp[integer(Data)].Kind in [ikNatLocal, ikNatGlobal] then
     4376              built[Integer(Data)] := 0;
     4377              if Imp[Integer(Data)].Kind in [ikNatLocal, ikNatGlobal] then
    43784378              begin
    4379                 RW[Player].NatBuilt[integer(Data)] := 0;
    4380                 case integer(Data) of
     4379                RW[Player].NatBuilt[Integer(Data)] := 0;
     4380                case Integer(Data) of
    43814381                  imGrWall:
    43824382                    GrWallContinent[Player] := -1;
     
    43854385                end;
    43864386              end;
    4387               inc(Flags, chImprovementSold);
     4387              Inc(Flags, chImprovementSold);
    43884388            end;
    43894389      end;
     
    43914391    sRebuildCityImprovement, sRebuildCityImprovement - sExecute:
    43924392      begin
    4393         OldImp := integer(Data);
     4393        OldImp := Integer(Data);
    43944394{$IFDEF TEXTLOG}CmdInfo := Format('RebuildCityImprovement P%d Loc%d: %d', [Player, RW[Player].City[Subject].Loc, OldImp]); {$ENDIF}
    43954395        if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0)
    43964396        then
    4397           result := eInvalid
     4397          Result := eInvalid
    43984398        else
    43994399        begin
    44004400          if (OldImp < 0) or (OldImp >= nImp) or
    44014401            not(Imp[OldImp].Kind in [ikCommon, ikNatLocal, ikNatGlobal]) then
    4402             result := eInvalid
     4402            Result := eInvalid
    44034403          else
    44044404            with RW[Player].City[Subject] do
     
    44064406                not(Imp[Project and cpIndex].Kind in [ikCommon, ikNatLocal,
    44074407                ikNatGlobal]) then
    4408                 result := eInvalid
     4408                Result := eInvalid
    44094409              else if (RW[Player].Government = gAnarchy) or
    44104410                (Flags and chCaptured <> 0) then
    4411                 result := eOutOfControl
     4411                Result := eOutOfControl
    44124412              else if Flags and chImprovementSold <> 0 then
    4413                 result := eOnlyOnce
     4413                Result := eOnlyOnce
    44144414              else if Command >= sExecute then
    44154415              begin
    4416                 inc(Prod, Imp[OldImp].Cost * BuildCostMod[Difficulty[Player]]
     4416                Inc(Prod, Imp[OldImp].Cost * BuildCostMod[Difficulty[Player]]
    44174417                  div 12 * 2 div 3);
    44184418                Project0 := Project0 and not cpCompleted;
     
    44314431                  end;
    44324432                end;
    4433                 inc(Flags, chImprovementSold);
     4433                Inc(Flags, chImprovementSold);
    44344434              end;
    44354435        end;
     
    44384438    sSetCityTiles, sSetCityTiles - sExecute:
    44394439      begin
    4440 {$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}
    44414441        if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0)
    44424442        then
    4443           result := eInvalid
     4443          Result := eInvalid
    44444444        else
    4445           result := SetCityTiles(Player, Subject, integer(Data),
     4445          Result := SetCityTiles(Player, Subject, Integer(Data),
    44464446            Command < sExecute);
    44474447      end;
     
    44604460    end
    44614461    else
    4462       result := eUnknown;
     4462      Result := eUnknown;
    44634463  end; { case command }
    44644464
    44654465  // do not log invalid and non-relevant commands
    4466   if result = eZOC_EnemySpotted then
     4466  if Result = eZOC_EnemySpotted then
    44674467  begin
    4468     assert(Mode = moPlaying);
     4468    Assert(Mode = moPlaying);
    44694469    CL.State := FormerCLState;
    44704470    IntServer(sIntDiscoverZOC, Player, 0, ZOCTile);
    44714471  end
    4472   else if result and rEffective = 0 then
     4472  else if Result and rEffective = 0 then
    44734473    if Mode < moPlaying then
    44744474    begin
    4475 {$IFDEF TEXTLOG}CmdInfo := Format('***ERROR (%x) ', [result]) + CmdInfo;
     4475{$IFDEF TEXTLOG}CmdInfo := Format('***ERROR (%x) ', [Result]) + CmdInfo;
    44764476      {$ENDIF}
    4477       LoadOK := false;
     4477      LoadOK := False;
    44784478    end
    44794479    else
     
    44814481      if logged then
    44824482        CL.State := FormerCLState;
    4483       if (result < rExecuted) and (Command >= sExecute) then
     4483      if (Result < rExecuted) and (Command >= sExecute) then
    44844484        PutMessage(1 shl 16 + 1, Format('INVALID: %d calls %x (%d)',
    44854485          [Player, Command, Subject]));
     
    44874487
    44884488  if (Command and (cClientEx or sExecute or sctMask) = sExecute or sctEndClient)
    4489     and (result >= rExecuted) then
     4489    and (Result >= rExecuted) then
    44904490    LastEndClientCommand := Command;
    4491 {$IFOPT O-}dec(nHandoverStack, 2); {$ENDIF}
     4491{$IFOPT O-}Dec(nHandoverStack, 2); {$ENDIF}
    44924492end;
    44934493
Note: See TracChangeset for help on using the changeset viewer.