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/AI/StdAI/CustomAI.pas

    r289 r447  
    1313  TCustomAI = class
    1414  public
    15     procedure Process(Command: integer; var Data);
     15    procedure Process(Command: Integer; var Data);
    1616
    1717    // overridables
    18     constructor Create(Nation: integer); virtual;
     18    constructor Create(Nation: Integer); virtual;
    1919    destructor Destroy; override;
    2020    procedure SetDataDefaults; virtual;
    2121    procedure SetDataRandom; virtual;
    2222    procedure OnBeforeEnemyAttack(UnitInfo: TUnitInfo;
    23       ToLoc, EndHealth, EndHealthDef: integer); virtual;
    24     procedure OnBeforeEnemyCapture(UnitInfo: TUnitInfo; ToLoc: integer); virtual;
     23      ToLoc, EndHealth, EndHealthDef: Integer); virtual;
     24    procedure OnBeforeEnemyCapture(UnitInfo: TUnitInfo; ToLoc: Integer); virtual;
    2525    procedure OnAfterEnemyAttack; virtual;
    2626    procedure OnAfterEnemyCapture; virtual;
    2727
    2828  protected
    29     me: integer; // index of the controlled nation
     29    Me: Integer; // index of the controlled nation
    3030    RO: ^TPlayerContext;
    3131    Map: ^TTileList;
     
    3434    MyModel: ^TModelList;
    3535
    36     cixStateImp: array[imPalace..imSpacePort] of integer;
     36    cixStateImp: array[imPalace..imSpacePort] of Integer;
    3737
    3838    // negotiation
    39     Opponent: integer; // nation i'm in negotiation with, -1 indicates no-negotiation mode
    40     MyAction, MyLastAction, OppoAction: integer;
     39    Opponent: Integer; // nation i'm in negotiation with, -1 indicates no-negotiation mode
     40    MyAction, MyLastAction, OppoAction: Integer;
    4141    MyOffer, MyLastOffer, OppoOffer: TOffer;
    4242
     
    4444    procedure DoTurn; virtual;
    4545    procedure DoNegotiation; virtual;
    46     function ChooseResearchAdvance: integer; virtual;
    47     function ChooseStealAdvance: integer; virtual;
    48     function ChooseGovernment: integer; virtual;
    49     function WantNegotiation(Nation: integer; NegoTime: TNegoTime): boolean; virtual;
    50     function OnNegoRejected_CancelTreaty: boolean; virtual;
     46    function ChooseResearchAdvance: Integer; virtual;
     47    function ChooseStealAdvance: Integer; virtual;
     48    function ChooseGovernment: Integer; virtual;
     49    function WantNegotiation(Nation: Integer; NegoTime: TNegoTime): Boolean; virtual;
     50    function OnNegoRejected_CancelTreaty: Boolean; virtual;
    5151
    5252    // general functions
    53     function IsResearched(Advance: integer): boolean;
    54     function ResearchCost: integer;
    55     function ChangeAttitude(Nation, Attitude: integer): integer;
    56     function Revolution: integer;
    57     function ChangeRates(Tax, Lux: integer): integer;
    58     function PrepareNewModel(Domain: integer): integer;
    59     function SetNewModelFeature(F, Count: integer): integer;
    60     function AdvanceResearchable(Advance: integer): boolean;
    61     function AdvanceStealable(Advance: integer): boolean;
    62     function GetJobProgress(Loc: integer; var JobProgress: TJobProgressData): boolean;
    63     function DebugMessage(Level: integer; Text: string): boolean;
    64     function SetDebugMap(var DebugMap): boolean;
     53    function IsResearched(Advance: Integer): Boolean;
     54    function ResearchCost: Integer;
     55    function ChangeAttitude(Nation, Attitude: Integer): Integer;
     56    function Revolution: Integer;
     57    function ChangeRates(Tax, Lux: Integer): Integer;
     58    function PrepareNewModel(Domain: Integer): Integer;
     59    function SetNewModelFeature(F, Count: Integer): Integer;
     60    function AdvanceResearchable(Advance: Integer): Boolean;
     61    function AdvanceStealable(Advance: Integer): Boolean;
     62    function GetJobProgress(Loc: Integer; var JobProgress: TJobProgressData): Boolean;
     63    function DebugMessage(Level: Integer; Text: string): Boolean;
     64    function SetDebugMap(var DebugMap): Boolean;
    6565
    6666    // unit functions
    67     procedure Unit_FindMyDefender(Loc: integer; var uix: integer);
    68     procedure Unit_FindEnemyDefender(Loc: integer; var euix: integer);
    69     function Unit_Move(uix, ToLoc: integer): integer;
    70     function Unit_Step(uix, ToLoc: integer): integer;
    71     function Unit_Attack(uix, ToLoc: integer): integer;
    72     function Unit_DoMission(uix, MissionType, ToLoc: integer): integer;
    73     function Unit_MoveForecast(uix, ToLoc: integer;
    74       var RemainingMovement: integer): boolean;
    75     function Unit_AttackForecast(uix, ToLoc, AttackMovement: integer;
    76       var RemainingHealth: integer): boolean;
    77     function Unit_DefenseForecast(euix, ToLoc: integer;
    78       var RemainingHealth: integer): boolean;
    79     function Unit_Disband(uix: integer): integer;
    80     function Unit_StartJob(uix, NewJob: integer): integer;
    81     function Unit_SetHomeHere(uix: integer): integer;
    82     function Unit_Load(uix: integer): integer;
    83     function Unit_Unload(uix: integer): integer;
    84     function Unit_SelectTransport(uix: integer): integer;
    85     function Unit_AddToCity(uix: integer): integer;
     67    procedure Unit_FindMyDefender(Loc: Integer; var uix: Integer);
     68    procedure Unit_FindEnemyDefender(Loc: Integer; var euix: Integer);
     69    function Unit_Move(uix, ToLoc: Integer): Integer;
     70    function Unit_Step(uix, ToLoc: Integer): Integer;
     71    function Unit_Attack(uix, ToLoc: Integer): Integer;
     72    function Unit_DoMission(uix, MissionType, ToLoc: Integer): Integer;
     73    function Unit_MoveForecast(uix, ToLoc: Integer;
     74      var RemainingMovement: Integer): Boolean;
     75    function Unit_AttackForecast(uix, ToLoc, AttackMovement: Integer;
     76      var RemainingHealth: Integer): Boolean;
     77    function Unit_DefenseForecast(euix, ToLoc: Integer;
     78      var RemainingHealth: Integer): Boolean;
     79    function Unit_Disband(uix: Integer): Integer;
     80    function Unit_StartJob(uix, NewJob: Integer): Integer;
     81    function Unit_SetHomeHere(uix: Integer): Integer;
     82    function Unit_Load(uix: Integer): Integer;
     83    function Unit_Unload(uix: Integer): Integer;
     84    function Unit_SelectTransport(uix: Integer): Integer;
     85    function Unit_AddToCity(uix: Integer): Integer;
    8686
    8787    // city functions
    88     procedure City_FindMyCity(Loc: integer; var cix: integer);
    89     procedure City_FindEnemyCity(Loc: integer; var ecix: integer);
    90     function City_HasProject(cix: integer): boolean;
    91     function City_CurrentImprovementProject(cix: integer): integer;
    92     function City_CurrentUnitProject(cix: integer): integer;
    93     function City_GetTileInfo(cix, TileLoc: integer; var TileInfo: TTileInfo): integer;
    94     function City_GetReport(cix: integer; var Report: TCityReport): integer;
    95     function City_GetHypoReport(cix, HypoTiles, HypoTax, HypoLux: integer;
    96       var Report: TCityReport): integer;
    97     function City_GetReportNew(cix: integer; var Report: TCityReportNew): integer;
    98     function City_GetHypoReportNew(cix, HypoTiles, HypoTaxRate, HypoLuxuryRate: integer;
    99       var Report: TCityReportNew): integer;
    100     function City_GetAreaInfo(cix: integer; var AreaInfo: TCityAreaInfo): integer;
    101     function City_StartUnitProduction(cix, mix: integer): integer;
    102     function City_StartEmigration(cix, mix: integer;
    103       AllowDisbandCity, AsConscripts: boolean): integer;
    104     function City_StartImprovement(cix, iix: integer): integer;
    105     function City_Improvable(cix, iix: integer): boolean;
    106     function City_StopProduction(cix: integer): integer;
    107     function City_BuyProject(cix: integer): integer;
    108     function City_SellImprovement(cix, iix: integer): integer;
    109     function City_RebuildImprovement(cix, iix: integer): integer;
    110     function City_SetTiles(cix, NewTiles: integer): integer;
    111     procedure City_OptimizeTiles(cix: integer; ResourceWeights: cardinal = rwMaxGrowth);
     88    procedure City_FindMyCity(Loc: Integer; var cix: Integer);
     89    procedure City_FindEnemyCity(Loc: Integer; var ecix: Integer);
     90    function City_HasProject(cix: Integer): Boolean;
     91    function City_CurrentImprovementProject(cix: Integer): Integer;
     92    function City_CurrentUnitProject(cix: Integer): Integer;
     93    function City_GetTileInfo(cix, TileLoc: Integer; var TileInfo: TTileInfo): Integer;
     94    function City_GetReport(cix: Integer; var Report: TCityReport): Integer;
     95    function City_GetHypoReport(cix, HypoTiles, HypoTax, HypoLux: Integer;
     96      var Report: TCityReport): Integer;
     97    function City_GetReportNew(cix: Integer; var Report: TCityReportNew): Integer;
     98    function City_GetHypoReportNew(cix, HypoTiles, HypoTaxRate, HypoLuxuryRate: Integer;
     99      var Report: TCityReportNew): Integer;
     100    function City_GetAreaInfo(cix: Integer; var AreaInfo: TCityAreaInfo): Integer;
     101    function City_StartUnitProduction(cix, mix: Integer): Integer;
     102    function City_StartEmigration(cix, mix: Integer;
     103      AllowDisbandCity, AsConscripts: Boolean): Integer;
     104    function City_StartImprovement(cix, iix: Integer): Integer;
     105    function City_Improvable(cix, iix: Integer): Boolean;
     106    function City_StopProduction(cix: Integer): Integer;
     107    function City_BuyProject(cix: Integer): Integer;
     108    function City_SellImprovement(cix, iix: Integer): Integer;
     109    function City_RebuildImprovement(cix, iix: Integer): Integer;
     110    function City_SetTiles(cix, NewTiles: Integer): Integer;
     111    procedure City_OptimizeTiles(cix: Integer; ResourceWeights: Cardinal = rwMaxGrowth);
    112112
    113113    // negotiation
    114     function Nego_CheckMyAction: integer;
     114    function Nego_CheckMyAction: Integer;
    115115
    116116  private
    117     HaveTurned: boolean;
     117    HaveTurned: Boolean;
    118118    UnwantedNego: set of 0..nPl - 1;
    119119    Contacted: set of 0..nPl - 1;
     
    125125  Server: TServerCall;
    126126  G: TNewGameData;
    127   RWDataSize, MapSize: integer;
    128   decompose24: cardinal;
    129   nodata: pointer;
     127  RWDataSize, MapSize: Integer;
     128  decompose24: Cardinal;
     129  nodata: Pointer;
    130130
    131131const
     
    139139
    140140type
    141   TVicinity8Loc = array[0..7] of integer;
    142   TVicinity21Loc = array[0..27] of integer;
     141  TVicinity8Loc = array[0..7] of Integer;
     142  TVicinity21Loc = array[0..27] of Integer;
    143143
    144144
    145145procedure Init(NewGameData: TNewGameData);
    146146
    147 procedure ab_to_Loc(Loc0, a, b: integer; var Loc: integer);
    148 procedure Loc_to_ab(Loc0, Loc: integer; var a, b: integer);
    149 procedure ab_to_V8(a, b: integer; var V8: integer);
    150 procedure V8_to_ab(V8: integer; var a, b: integer);
    151 procedure ab_to_V21(a, b: integer; var V21: integer);
    152 procedure V21_to_ab(V21: integer; var a, b: integer);
    153 procedure V8_to_Loc(Loc0: integer; var VicinityLoc: TVicinity8Loc);
    154 procedure V21_to_Loc(Loc0: integer; var VicinityLoc: TVicinity21Loc);
    155 function Distance(Loc0, Loc1: integer): integer;
     147procedure ab_to_Loc(Loc0, A, B: Integer; var Loc: Integer);
     148procedure Loc_to_ab(Loc0, Loc: Integer; var A, B: Integer);
     149procedure ab_to_V8(A, B: Integer; var V8: Integer);
     150procedure V8_to_ab(V8: Integer; var A, B: Integer);
     151procedure ab_to_V21(A, B: Integer; var V21: Integer);
     152procedure V21_to_ab(V21: Integer; var A, B: Integer);
     153procedure V8_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity8Loc);
     154procedure V21_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity21Loc);
     155function Distance(Loc0, Loc1: Integer): Integer;
    156156
    157157
     
    159159
    160160const
    161   ab_v8: array[-4..4] of integer = (5, 6, 7, 4, -1, 0, 3, 2, 1);
    162   v8_a: array[0..7] of integer = (1, 1, 0, -1, -1, -1, 0, 1);
    163   v8_b: array[0..7] of integer = (0, 1, 1, 1, 0, -1, -1, -1);
    164 
    165 
    166 procedure ab_to_Loc(Loc0, a, b: integer; var Loc: integer);
     161  ab_v8: array[-4..4] of Integer = (5, 6, 7, 4, -1, 0, 3, 2, 1);
     162  v8_a: array[0..7] of Integer = (1, 1, 0, -1, -1, -1, 0, 1);
     163  v8_b: array[0..7] of Integer = (0, 1, 1, 1, 0, -1, -1, -1);
     164
     165
     166procedure ab_to_Loc(Loc0, A, B: Integer; var Loc: Integer);
    167167{relative location from Loc0}
    168168var
    169   y0: integer;
    170 begin
    171   assert((Loc0 >= 0) and (Loc0 < MapSize) and (a - b + G.lx >= 0));
    172   y0 := cardinal(Loc0) * decompose24 shr 24;
    173   Loc := (Loc0 + (a - b + y0 and 1 + G.lx + G.lx) shr 1) mod G.lx + G.lx * (y0 + a + b);
     169  y0: Integer;
     170begin
     171  Assert((Loc0 >= 0) and (Loc0 < MapSize) and (A - B + G.lx >= 0));
     172  y0 := Cardinal(Loc0) * decompose24 shr 24;
     173  Loc := (Loc0 + (A - B + y0 and 1 + G.lx + G.lx) shr 1) mod G.lx + G.lx * (y0 + A + B);
    174174  if Loc >= MapSize then
    175175    Loc := -$1000;
    176176end;
    177177
    178 procedure Loc_to_ab(Loc0, Loc: integer; var a, b: integer);
     178procedure Loc_to_ab(Loc0, Loc: Integer; var A, B: Integer);
    179179{$IFDEF FPC}// freepascal
    180180var
    181   dx, dy: integer;
     181  dx, dy: Integer;
    182182begin
    183183  dx := ((Loc mod G.lx * 2 + Loc div G.lx and 1) - (Loc0 mod G.lx * 2 + Loc0 div
    184184    G.lx and 1) + 3 * G.lx) mod (2 * G.lx) - G.lx;
    185185  dy := Loc div G.lx - Loc0 div G.lx;
    186   a := (dx + dy) div 2;
    187   b := (dy - dx) div 2;
     186  A := (dx + dy) div 2;
     187  B := (dy - dx) div 2;
    188188end;
    189189
     
    195195// calculate
    196196push ecx
    197 div byte ptr [G]
     197div Byte ptr [G]
    198198xor ebx,ebx
    199199mov bl,ah  // ebx:=Loc0 mod G.lx
     
    201201and ecx,$000000FF // ecx:=Loc0 div G.lx
    202202mov eax,edx
    203 div byte ptr [G]
     203div Byte ptr [G]
    204204xor edx,edx
    205205mov dl,ah // edx:=Loc mod G.lx
     
    218218mov edx,dword ptr [G]
    219219cmp eax,edx
    220 jl @a
     220jl @A
    221221  sub eax,edx
    222222  sub eax,edx
    223223  jmp @ok
    224 @a:
     224@A:
    225225neg edx
    226226cmp eax,edx
     
    235235add eax,ebx
    236236sar edx,1 // edx:=b
    237 mov ebx,[b]
     237mov ebx,[B]
    238238mov [ebx],edx
    239239sar eax,1 // eax:=a
    240 mov [a],eax
     240mov [A],eax
    241241
    242242pop ebx
     
    244244{$ENDIF}
    245245
    246 procedure ab_to_V8(a, b: integer; var V8: integer);
    247 begin
    248   assert((abs(a) <= 1) and (abs(b) <= 1) and ((a <> 0) or (b <> 0)));
    249   V8 := ab_v8[2 * b + b + a];
    250 end;
    251 
    252 procedure V8_to_ab(V8: integer; var a, b: integer);
    253 begin
    254   a := v8_a[V8];
    255   b := V8_b[V8];
    256 end;
    257 
    258 procedure ab_to_V21(a, b: integer; var V21: integer);
    259 begin
    260   V21 := (a + b + 3) shl 2 + (a - b + 3) shr 1;
    261 end;
    262 
    263 procedure V21_to_ab(V21: integer; var a, b: integer);
    264 var
    265   dx, dy: integer;
     246procedure ab_to_V8(A, B: Integer; var V8: Integer);
     247begin
     248  Assert((abs(A) <= 1) and (abs(B) <= 1) and ((A <> 0) or (B <> 0)));
     249  V8 := ab_v8[2 * B + B + A];
     250end;
     251
     252procedure V8_to_ab(V8: Integer; var A, B: Integer);
     253begin
     254  A := v8_a[V8];
     255  B := V8_b[V8];
     256end;
     257
     258procedure ab_to_V21(A, B: Integer; var V21: Integer);
     259begin
     260  V21 := (A + B + 3) shl 2 + (A - B + 3) shr 1;
     261end;
     262
     263procedure V21_to_ab(V21: Integer; var A, B: Integer);
     264var
     265  dx, dy: Integer;
    266266begin
    267267  dy := V21 shr 2 - 3;
    268268  dx := V21 and 3 shl 1 - 3 + (dy + 3) and 1;
    269   a := (dx + dy) div 2;
    270   b := (dy - dx) div 2;
    271 end;
    272 
    273 procedure V8_to_Loc(Loc0: integer; var VicinityLoc: TVicinity8Loc);
    274 var
    275   x0, y0, lx: integer;
     269  A := (dx + dy) div 2;
     270  B := (dy - dx) div 2;
     271end;
     272
     273procedure V8_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity8Loc);
     274var
     275  x0, y0, lx: Integer;
    276276begin
    277277  lx := G.lx;
    278   y0 := cardinal(Loc0) * decompose24 shr 24;
     278  y0 := Cardinal(Loc0) * decompose24 shr 24;
    279279  x0 := Loc0 - y0 * lx; // Loc0 mod lx;
    280280  VicinityLoc[1] := Loc0 + lx * 2;
     
    323323end;
    324324
    325 procedure V21_to_Loc(Loc0: integer; var VicinityLoc: TVicinity21Loc);
    326 var
    327   dx, dy, bit, y0, xComp, yComp, xComp0, xCompSwitch: integer;
    328   dst: ^integer;
    329 begin
    330   y0 := cardinal(Loc0) * decompose24 shr 24;
     325procedure V21_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity21Loc);
     326var
     327  dx, dy, bit, y0, xComp, yComp, xComp0, xCompSwitch: Integer;
     328  dst: ^Integer;
     329begin
     330  y0 := Cardinal(Loc0) * decompose24 shr 24;
    331331  xComp0 := Loc0 - y0 * G.lx - 1; // Loc0 mod G.lx -1
    332332  xCompSwitch := xComp0 - 1 + y0 and 1;
     
    368368end;
    369369
    370 function Distance(Loc0, Loc1: integer): integer;
    371 var
    372   a, b, dx, dy: integer;
    373 begin
    374   Loc_to_ab(Loc0, Loc1, a, b);
    375   dx := abs(a - b);
    376   dy := abs(a + b);
     370function Distance(Loc0, Loc1: Integer): Integer;
     371var
     372  A, B, dx, dy: Integer;
     373begin
     374  Loc_to_ab(Loc0, Loc1, A, B);
     375  dx := abs(A - B);
     376  dy := abs(A + B);
    377377  Result := dx + dy + abs(dx - dy) shr 1;
    378378end;
     
    381381procedure Init(NewGameData: TNewGameData);
    382382{$IFDEF DEBUG}var
    383   Loc: integer;
     383  Loc: Integer;
    384384{$ENDIF}
    385385begin
     
    389389{$IFDEF DEBUG}
    390390  for Loc := 0 to MapSize - 1 do
    391     assert(cardinal(Loc) * decompose24 shr 24 = cardinal(Loc div G.lx));
     391    Assert(Cardinal(Loc) * decompose24 shr 24 = Cardinal(Loc div G.lx));
    392392{$ENDIF}
    393393end;
    394394
    395395
    396 constructor TCustomAI.Create(Nation: integer);
     396constructor TCustomAI.Create(Nation: Integer);
    397397begin
    398398  inherited Create;
    399   me := Nation;
    400   RO := pointer(G.RO[Nation]);
    401   Map := pointer(RO.Map);
    402   MyUnit := pointer(RO.Un);
    403   MyCity := pointer(RO.City);
    404   MyModel := pointer(RO.Model);
     399  Me := Nation;
     400  RO := Pointer(G.RO[Nation]);
     401  Map := Pointer(RO.Map);
     402  MyUnit := Pointer(RO.Un);
     403  MyCity := Pointer(RO.City);
     404  MyModel := Pointer(RO.Model);
    405405  Opponent := -1;
    406406end;
     
    408408destructor TCustomAI.Destroy;
    409409begin
    410   Server(sSetDebugMap, me, 0, nodata^);
    411 end;
    412 
    413 
    414 procedure TCustomAI.Process(Command: integer; var Data);
    415 var
    416   Nation, NewResearch, NewGov, Count, ad, cix, iix: integer;
     410  Server(sSetDebugMap, Me, 0, nodata^);
     411end;
     412
     413
     414procedure TCustomAI.Process(Command: Integer; var Data);
     415var
     416  Nation, NewResearch, NewGov, Count, ad, cix, iix: Integer;
    417417  NegoTime: TNegoTime;
    418418begin
     
    420420    cTurn, cContinue:
    421421    begin
    422       if RO.Alive and (1 shl me) = 0 then
     422      if RO.Alive and (1 shl Me) = 0 then
    423423      begin // I'm dead, huhu
    424         Server(sTurn, me, 0, nodata^);
    425         exit;
     424        Server(sTurn, Me, 0, nodata^);
     425        Exit;
    426426      end;
    427427      if Command = cTurn then
    428428      begin
    429         fillchar(cixStateImp, sizeof(cixStateImp), $FF);
     429        FillChar(cixStateImp, SizeOf(cixStateImp), $FF);
    430430        for cix := 0 to RO.nCity - 1 do
    431431          if MyCity[cix].Loc >= 0 then
     
    437437          NewGov := ChooseGovernment;
    438438          if NewGov > gAnarchy then
    439             Server(sSetGovernment, me, NewGov, nodata^);
     439            Server(sSetGovernment, Me, NewGov, nodata^);
    440440        end;
    441441        HaveTurned := False;
     
    446446        if OnNegoRejected_CancelTreaty then
    447447          if RO.Treaty[Opponent] >= trPeace then
    448             if Server(sCancelTreaty, me, 0, nodata^) < rExecuted then
    449               assert(False);
     448            if Server(sCancelTreaty, Me, 0, nodata^) < rExecuted then
     449              Assert(False);
    450450      end
    451451      else
     
    459459        if RO.Government <> gAnarchy then
    460460          for Nation := 0 to nPl - 1 do
    461             if (Nation <> me) and (1 shl Nation and RO.Alive <> 0) and
     461            if (Nation <> Me) and (1 shl Nation and RO.Alive <> 0) and
    462462              (RO.Treaty[Nation] >= trNone) and not (Nation in Contacted) and not
    463463              (Nation in UnwantedNego) and
    464               (Server(scContact - sExecute + Nation shl 4, me, 0, nodata^) >= rExecuted) then
     464              (Server(scContact - sExecute + Nation shl 4, Me, 0, nodata^) >= rExecuted) then
    465465              if WantNegotiation(Nation, NegoTime) then
    466466              begin
    467                 if Server(scContact + Nation shl 4, me, 0, nodata^) >= rExecuted then
     467                if Server(scContact + Nation shl 4, Me, 0, nodata^) >= rExecuted then
    468468                begin
    469                   include(Contacted, Nation);
     469                  Include(Contacted, Nation);
    470470                  Opponent := Nation;
    471471                  MyAction := scContact;
    472                   exit;
     472                  Exit;
    473473                end;
    474474              end
    475475              else
    476                 include(UnwantedNego, Nation);
     476                Include(UnwantedNego, Nation);
    477477        if NegoTime = BeginOfTurn then
    478478        begin
     
    483483        end
    484484        else
    485           break;
     485          Break;
    486486      until False;
    487487      if RO.Happened and phTech <> 0 then
     
    499499            end;
    500500        end;
    501         Server(sSetResearch, me, NewResearch, nodata^);
     501        Server(sSetResearch, Me, NewResearch, nodata^);
    502502      end;
    503       if Server(sTurn, me, 0, nodata^) < rExecuted then
    504         assert(False);
     503      if Server(sTurn, Me, 0, nodata^) < rExecuted then
     504        Assert(False);
    505505    end;
    506506    scContact:
    507       if WantNegotiation(integer(Data), EnemyCalled) then
     507      if WantNegotiation(Integer(Data), EnemyCalled) then
    508508      begin
    509         if Server(scDipStart, me, 0, nodata^) < rExecuted then
    510           assert(False);
    511         Opponent := integer(Data);
     509        if Server(scDipStart, Me, 0, nodata^) < rExecuted then
     510          Assert(False);
     511        Opponent := Integer(Data);
    512512        MyAction := scDipStart;
    513513      end
    514514      else
    515515      begin
    516         if Server(scReject, me, 0, nodata^) < rExecuted then
    517           assert(False);
     516        if Server(scReject, Me, 0, nodata^) < rExecuted then
     517          Assert(False);
    518518      end;
    519519    scDipStart, scDipNotice, scDipAccept, scDipCancelTreaty, scDipOffer, scDipBreak:
     
    538538      end;
    539539      DoNegotiation;
    540       assert((MyAction = scDipNotice) or (MyAction = scDipAccept) or
     540      Assert((MyAction = scDipNotice) or (MyAction = scDipAccept) or
    541541        (MyAction = scDipCancelTreaty) or (MyAction = scDipOffer) or (MyAction = scDipBreak));
    542542      if MyAction = scDipOffer then
    543         Server(MyAction, me, 0, MyOffer)
     543        Server(MyAction, Me, 0, MyOffer)
    544544      else
    545         Server(MyAction, me, 0, nodata^);
     545        Server(MyAction, Me, 0, nodata^);
    546546    end;
    547547    cShowEndContact:
     
    568568
    569569procedure TCustomAI.OnBeforeEnemyAttack(UnitInfo: TUnitInfo;
    570   ToLoc, EndHealth, EndHealthDef: integer);
    571 begin
    572 end;
    573 
    574 procedure TCustomAI.OnBeforeEnemyCapture(UnitInfo: TUnitInfo; ToLoc: integer);
     570  ToLoc, EndHealth, EndHealthDef: Integer);
     571begin
     572end;
     573
     574procedure TCustomAI.OnBeforeEnemyCapture(UnitInfo: TUnitInfo; ToLoc: Integer);
    575575begin
    576576end;
     
    584584end;
    585585
    586 function TCustomAI.ChooseResearchAdvance: integer;
     586function TCustomAI.ChooseResearchAdvance: Integer;
    587587begin
    588588  Result := -1;
    589589end;
    590590
    591 function TCustomAI.ChooseStealAdvance: integer;
     591function TCustomAI.ChooseStealAdvance: Integer;
    592592begin
    593593  Result := -1;
    594594end;
    595595
    596 function TCustomAI.ChooseGovernment: integer;
     596function TCustomAI.ChooseGovernment: Integer;
    597597begin
    598598  Result := gDespotism;
    599599end;
    600600
    601 function TCustomAI.WantNegotiation(Nation: integer; NegoTime: TNegoTime): boolean;
     601function TCustomAI.WantNegotiation(Nation: Integer; NegoTime: TNegoTime): Boolean;
    602602begin
    603603  Result := False;
    604604end;
    605605
    606 function TCustomAI.OnNegoRejected_CancelTreaty: boolean;
     606function TCustomAI.OnNegoRejected_CancelTreaty: Boolean;
    607607begin
    608608  Result := False;
     
    613613procedure TCustomAI.StealAdvance;
    614614var
    615   Steal, ad, Count: integer;
     615  Steal, ad, Count: Integer;
    616616begin
    617617  Steal := ChooseStealAdvance;
     
    628628  end;
    629629  if Steal >= 0 then
    630     Server(sStealTech, me, Steal, nodata^);
     630    Server(sStealTech, Me, Steal, nodata^);
    631631  RO.Happened := RO.Happened and not phStealTech;
    632632end;
    633633
    634 function TCustomAI.IsResearched(Advance: integer): boolean;
     634function TCustomAI.IsResearched(Advance: Integer): Boolean;
    635635begin
    636636  Result := (Advance = preNone) or (Advance <> preNA) and (RO.Tech[Advance] >= tsApplicable);
    637637end;
    638638
    639 function TCustomAI.ResearchCost: integer;
    640 begin
    641   Server(sGetTechCost, me, 0, Result);
    642 end;
    643 
    644 function TCustomAI.ChangeAttitude(Nation, Attitude: integer): integer;
    645 begin
    646   Result := Server(sSetAttitude + Nation shl 4, me, Attitude, nodata^);
    647 end;
    648 
    649 function TCustomAI.Revolution: integer;
    650 begin
    651   Result := Server(sRevolution, me, 0, nodata^);
    652 end;
    653 
    654 function TCustomAI.ChangeRates(Tax, Lux: integer): integer;
    655 begin
    656   Result := Server(sSetRates, me, Tax div 10 and $f + Lux div 10 and $f shl 4, nodata^);
    657 end;
    658 
    659 function TCustomAI.PrepareNewModel(Domain: integer): integer;
    660 begin
    661   Result := Server(sCreateDevModel, me, Domain, nodata^);
    662 end;
    663 
    664 function TCustomAI.SetNewModelFeature(F, Count: integer): integer;
    665 begin
    666   Result := Server(sSetDevModelCap + Count shl 4, me, F, nodata^);
    667 end;
    668 
    669 function TCustomAI.AdvanceResearchable(Advance: integer): boolean;
    670 begin
    671   Result := Server(sSetResearch - sExecute, me, Advance, nodata^) >= rExecuted;
    672 end;
    673 
    674 function TCustomAI.AdvanceStealable(Advance: integer): boolean;
    675 begin
    676   Result := Server(sStealTech - sExecute, me, Advance, nodata^) >= rExecuted;
    677 end;
    678 
    679 function TCustomAI.GetJobProgress(Loc: integer;
    680   var JobProgress: TJobProgressData): boolean;
    681 begin
    682   Result := Server(sGetJobProgress, me, Loc, JobProgress) >= rExecuted;
    683 end;
    684 
    685 function TCustomAI.DebugMessage(Level: integer; Text: string): boolean;
    686 begin
    687   Text := copy('P' + char(48 + me) + ' ' + Text, 1, 254);
    688   Server(sMessage, me, Level, PChar(Text)^);
     639function TCustomAI.ResearchCost: Integer;
     640begin
     641  Server(sGetTechCost, Me, 0, Result);
     642end;
     643
     644function TCustomAI.ChangeAttitude(Nation, Attitude: Integer): Integer;
     645begin
     646  Result := Server(sSetAttitude + Nation shl 4, Me, Attitude, nodata^);
     647end;
     648
     649function TCustomAI.Revolution: Integer;
     650begin
     651  Result := Server(sRevolution, Me, 0, nodata^);
     652end;
     653
     654function TCustomAI.ChangeRates(Tax, Lux: Integer): Integer;
     655begin
     656  Result := Server(sSetRates, Me, Tax div 10 and $F + Lux div 10 and $F shl 4, nodata^);
     657end;
     658
     659function TCustomAI.PrepareNewModel(Domain: Integer): Integer;
     660begin
     661  Result := Server(sCreateDevModel, Me, Domain, nodata^);
     662end;
     663
     664function TCustomAI.SetNewModelFeature(F, Count: Integer): Integer;
     665begin
     666  Result := Server(sSetDevModelCap + Count shl 4, Me, F, nodata^);
     667end;
     668
     669function TCustomAI.AdvanceResearchable(Advance: Integer): Boolean;
     670begin
     671  Result := Server(sSetResearch - sExecute, Me, Advance, nodata^) >= rExecuted;
     672end;
     673
     674function TCustomAI.AdvanceStealable(Advance: Integer): Boolean;
     675begin
     676  Result := Server(sStealTech - sExecute, Me, Advance, nodata^) >= rExecuted;
     677end;
     678
     679function TCustomAI.GetJobProgress(Loc: Integer;
     680  var JobProgress: TJobProgressData): Boolean;
     681begin
     682  Result := Server(sGetJobProgress, Me, Loc, JobProgress) >= rExecuted;
     683end;
     684
     685function TCustomAI.DebugMessage(Level: Integer; Text: string): Boolean;
     686begin
     687  Text := Copy('P' + char(48 + Me) + ' ' + Text, 1, 254);
     688  Server(sMessage, Me, Level, PChar(Text)^);
    689689
    690690  Result := True;
     
    693693end;
    694694
    695 function TCustomAI.SetDebugMap(var DebugMap): boolean;
    696 begin
    697   Server(sSetDebugMap, me, 0, DebugMap);
     695function TCustomAI.SetDebugMap(var DebugMap): Boolean;
     696begin
     697  Server(sSetDebugMap, Me, 0, DebugMap);
    698698
    699699  Result := True;
     
    702702end;
    703703
    704 procedure TCustomAI.Unit_FindMyDefender(Loc: integer; var uix: integer);
    705 begin
    706   if Server(sGetDefender, me, Loc, uix) < rExecuted then
     704procedure TCustomAI.Unit_FindMyDefender(Loc: Integer; var uix: Integer);
     705begin
     706  if Server(sGetDefender, Me, Loc, uix) < rExecuted then
    707707    uix := -1;
    708708end;
    709709
    710 procedure TCustomAI.Unit_FindEnemyDefender(Loc: integer; var euix: integer);
     710procedure TCustomAI.Unit_FindEnemyDefender(Loc: Integer; var euix: Integer);
    711711begin
    712712  euix := RO.nEnemyUn - 1;
     
    715715end;
    716716
    717 function TCustomAI.Unit_Move(uix, ToLoc: integer): integer;
    718 var
    719   Step: integer;
    720   DestinationReached: boolean;
     717function TCustomAI.Unit_Move(uix, ToLoc: Integer): Integer;
     718var
     719  Step: Integer;
     720  DestinationReached: Boolean;
    721721  Advice: TMoveAdviceData;
    722722begin
    723   assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0)); // is a unit
     723  Assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0)); // is a unit
    724724{Loc_to_ab(MyUnit[uix].Loc,ToLoc,a,b);
    725 assert((a<>0) or (b<>0));
    726 if (a>=-1) and (a<=1) and (b>=-1) and (b<=1) then
     725Assert((A<>0) or (B<>0));
     726if (A>=-1) and (A<=1) and (B>=-1) and (B<=1) then
    727727  begin // move to adjacent tile
    728   !!!problem: if move is invalid, return codes are not consistent with other branch (eNoWay)
     728  !!!problem: if Move is invalid, return codes are not consistent with other branch (eNoWay)
    729729  Advice.nStep:=1;
    730   Advice.dx[0]:=a-b;
    731   Advice.dy[0]:=a+b;
     730  Advice.dx[0]:=A-B;
     731  Advice.dy[0]:=A+B;
    732732  Advice.MoreTurns:=0;
    733733  Advice.MaxHostile_MovementLeft:=MyUnit[uix].Movement;
    734   result:=eOK;
     734  Result:=eOK;
    735735  end
    736736else}
     
    739739    Advice.MoreTurns := 9999;
    740740    Advice.MaxHostile_MovementLeft := 100;
    741     Result := Server(sGetMoveAdvice, me, uix, Advice);
     741    Result := Server(sGetMoveAdvice, Me, uix, Advice);
    742742  end;
    743743  if Result = eOk then
     
    755755        begin
    756756          DestinationReached := True;
    757           break;
     757          Break;
    758758        end // stop next to destination
    759759        else if Step = Advice.nStep then
     
    761761
    762762      if (Step = Advice.nStep) or (Result <> eOK) and (Result <> eLoaded) then
    763         break;
     763        Break;
    764764
    765765      Result := Server(sMoveUnit + (Advice.dx[Step] and 7) shl 4 +
    766         (Advice.dy[Step] and 7) shl 7, me, uix, nodata^);
     766        (Advice.dy[Step] and 7) shl 7, Me, uix, nodata^);
    767767      Inc(Step);
    768768      if RO.Happened and phStealTech <> 0 then
     
    779779end;
    780780
    781 function TCustomAI.Unit_Step(uix, ToLoc: integer): integer;
    782 var
    783   a, b: integer;
    784 begin
    785   Loc_to_ab(MyUnit[uix].Loc, ToLoc, a, b);
    786   assert(((a <> 0) or (b <> 0)) and (a >= -1) and (a <= 1) and (b >= -1) and (b <= 1));
    787   Result := Server(sMoveUnit + ((a - b) and 7) shl 4 + ((a + b) and 7) shl 7, me, uix, nodata^);
     781function TCustomAI.Unit_Step(uix, ToLoc: Integer): Integer;
     782var
     783  A, B: Integer;
     784begin
     785  Loc_to_ab(MyUnit[uix].Loc, ToLoc, A, B);
     786  Assert(((A <> 0) or (B <> 0)) and (A >= -1) and (A <= 1) and (B >= -1) and (B <= 1));
     787  Result := Server(sMoveUnit + ((A - B) and 7) shl 4 + ((A + B) and 7) shl 7, Me, uix, nodata^);
    788788  if RO.Happened and phStealTech <> 0 then
    789789    StealAdvance;
    790790end;
    791791
    792 function TCustomAI.Unit_Attack(uix, ToLoc: integer): integer;
    793 var
    794   a, b: integer;
    795 begin
    796   assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0) // is a unit
     792function TCustomAI.Unit_Attack(uix, ToLoc: Integer): Integer;
     793var
     794  A, B: Integer;
     795begin
     796  Assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0) // is a unit
    797797    and ((Map[ToLoc] and (fUnit or fOwned) = fUnit) // is an attack
    798798    or (Map[ToLoc] and (fCity or fOwned) = fCity) and
    799799    (MyModel[MyUnit[uix].mix].Domain <> dGround))); // is a bombardment
    800   Loc_to_ab(MyUnit[uix].Loc, ToLoc, a, b);
    801   assert(((a <> 0) or (b <> 0)) and (a >= -1) and (a <= 1) and (b >= -1) and (b <= 1));
     800  Loc_to_ab(MyUnit[uix].Loc, ToLoc, A, B);
     801  Assert(((A <> 0) or (B <> 0)) and (A >= -1) and (A <= 1) and (B >= -1) and (B <= 1));
    802802  // attack to adjacent tile
    803   Result := Server(sMoveUnit + (a - b) and 7 shl 4 + (a + b) and 7 shl 7, me, uix, nodata^);
    804 end;
    805 
    806 function TCustomAI.Unit_DoMission(uix, MissionType, ToLoc: integer): integer;
    807 var
    808   a, b: integer;
    809 begin
    810   Result := Server(sSetSpyMission + MissionType shl 4, me, 0, nodata^);
     803  Result := Server(sMoveUnit + (A - B) and 7 shl 4 + (A + B) and 7 shl 7, Me, uix, nodata^);
     804end;
     805
     806function TCustomAI.Unit_DoMission(uix, MissionType, ToLoc: Integer): Integer;
     807var
     808  A, B: Integer;
     809begin
     810  Result := Server(sSetSpyMission + MissionType shl 4, Me, 0, nodata^);
    811811  if Result >= rExecuted then
    812812  begin
    813     assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0) // is a unit
     813    Assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0) // is a unit
    814814      and (MyModel[MyUnit[uix].mix].Kind = mkDiplomat)); // is a commando
    815     Loc_to_ab(MyUnit[uix].Loc, ToLoc, a, b);
    816     assert(((a <> 0) or (b <> 0)) and (a >= -1) and (a <= 1) and (b >= -1) and (b <= 1));
     815    Loc_to_ab(MyUnit[uix].Loc, ToLoc, A, B);
     816    Assert(((A <> 0) or (B <> 0)) and (A >= -1) and (A <= 1) and (B >= -1) and (B <= 1));
    817817    // city must be adjacent
    818     Result := Server(sMoveUnit - sExecute + (a - b) and 7 shl 4 + (a + b) and 7 shl 7, me, uix, nodata^);
     818    Result := Server(sMoveUnit - sExecute + (A - B) and 7 shl 4 + (A + B) and 7 shl 7, Me, uix, nodata^);
    819819    if Result = eMissionDone then
    820       Result := Server(sMoveUnit + (a - b) and 7 shl 4 + (a + b) and 7 shl 7, me, uix, nodata^)
     820      Result := Server(sMoveUnit + (A - B) and 7 shl 4 + (A + B) and 7 shl 7, Me, uix, nodata^)
    821821    else if (Result <> eNoTime_Move) and (Result <> eTreaty) and (Result <> eNoTurn) then
    822822      Result := eInvalid; // not a special commando mission!
     
    824824end;
    825825
    826 function TCustomAI.Unit_MoveForecast(uix, ToLoc: integer;
    827   var RemainingMovement: integer): boolean;
     826function TCustomAI.Unit_MoveForecast(uix, ToLoc: Integer;
     827  var RemainingMovement: Integer): Boolean;
    828828var
    829829  Advice: TMoveAdviceData;
    830830begin
    831   assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0)); // is a unit
     831  Assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0)); // is a unit
    832832  Advice.ToLoc := ToLoc;
    833833  Advice.MoreTurns := 0;
    834834  Advice.MaxHostile_MovementLeft := 100;
    835   if Server(sGetMoveAdvice, me, uix, Advice) = eOk then
     835  if Server(sGetMoveAdvice, Me, uix, Advice) = eOk then
    836836  begin
    837837    RemainingMovement := Advice.MaxHostile_MovementLeft;
     
    846846
    847847// negative RemainingHealth is remaining helth of defender if lost
    848 function TCustomAI.Unit_AttackForecast(uix, ToLoc, AttackMovement: integer;
    849   var RemainingHealth: integer): boolean;
     848function TCustomAI.Unit_AttackForecast(uix, ToLoc, AttackMovement: Integer;
     849  var RemainingHealth: Integer): Boolean;
    850850var
    851851  BattleForecast: TBattleForecast;
    852852begin
    853   assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0) // is a unit
     853  Assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0) // is a unit
    854854    and (Map[ToLoc] and (fUnit or fOwned) = fUnit)); // is an attack
    855855  RemainingHealth := -$100;
     
    858858    with MyUnit[uix] do
    859859    begin
    860       BattleForecast.pAtt := me;
     860      BattleForecast.pAtt := Me;
    861861      BattleForecast.mixAtt := mix;
    862862      BattleForecast.HealthAtt := Health;
     
    864864      BattleForecast.FlagsAtt := Flags;
    865865      BattleForecast.Movement := AttackMovement;
    866       if Server(sGetBattleForecast, me, ToLoc, BattleForecast) >= rExecuted then
     866      if Server(sGetBattleForecast, Me, ToLoc, BattleForecast) >= rExecuted then
    867867      begin
    868868        if BattleForecast.EndHealthAtt > 0 then
     
    875875end;
    876876
    877 function TCustomAI.Unit_DefenseForecast(euix, ToLoc: integer;
    878   var RemainingHealth: integer): boolean;
     877function TCustomAI.Unit_DefenseForecast(euix, ToLoc: Integer;
     878  var RemainingHealth: Integer): Boolean;
    879879var
    880880  BattleForecast: TBattleForecast;
    881881begin
    882   assert((euix >= 0) and (euix < RO.nEnemyUn) and (RO.EnemyUn[euix].Loc >= 0) // is an enemy unit
     882  Assert((euix >= 0) and (euix < RO.nEnemyUn) and (RO.EnemyUn[euix].Loc >= 0) // is an enemy unit
    883883    and (Map[ToLoc] and (fUnit or fOwned) = (fUnit or fOwned))); // is an attack
    884884  RemainingHealth := $100;
     
    892892    BattleForecast.FlagsAtt := Flags;
    893893    BattleForecast.Movement := 100;
    894     if Server(sGetBattleForecast, me, ToLoc, BattleForecast) >= rExecuted then
     894    if Server(sGetBattleForecast, Me, ToLoc, BattleForecast) >= rExecuted then
    895895    begin
    896896      if BattleForecast.EndHealthDef > 0 then
     
    903903end;
    904904
    905 function TCustomAI.Unit_Disband(uix: integer): integer;
    906 begin
    907   Result := Server(sRemoveUnit, me, uix, nodata^);
    908 end;
    909 
    910 function TCustomAI.Unit_StartJob(uix, NewJob: integer): integer;
    911 begin
    912   Result := Server(sStartJob + NewJob shl 4, me, uix, nodata^);
    913 end;
    914 
    915 function TCustomAI.Unit_SetHomeHere(uix: integer): integer;
    916 begin
    917   Result := Server(sSetUnitHome, me, uix, nodata^);
    918 end;
    919 
    920 function TCustomAI.Unit_Load(uix: integer): integer;
    921 begin
    922   Result := Server(sLoadUnit, me, uix, nodata^);
    923 end;
    924 
    925 function TCustomAI.Unit_Unload(uix: integer): integer;
    926 begin
    927   Result := Server(sUnloadUnit, me, uix, nodata^);
    928 end;
    929 
    930 function TCustomAI.Unit_AddToCity(uix: integer): integer;
    931 begin
    932   Result := Server(sAddToCity, me, uix, nodata^);
    933 end;
    934 
    935 function TCustomAI.Unit_SelectTransport(uix: integer): integer;
    936 begin
    937   Result := Server(sSelectTransport, me, uix, nodata^);
    938 end;
    939 
    940 
    941 procedure TCustomAI.City_FindMyCity(Loc: integer; var cix: integer);
     905function TCustomAI.Unit_Disband(uix: Integer): Integer;
     906begin
     907  Result := Server(sRemoveUnit, Me, uix, nodata^);
     908end;
     909
     910function TCustomAI.Unit_StartJob(uix, NewJob: Integer): Integer;
     911begin
     912  Result := Server(sStartJob + NewJob shl 4, Me, uix, nodata^);
     913end;
     914
     915function TCustomAI.Unit_SetHomeHere(uix: Integer): Integer;
     916begin
     917  Result := Server(sSetUnitHome, Me, uix, nodata^);
     918end;
     919
     920function TCustomAI.Unit_Load(uix: Integer): Integer;
     921begin
     922  Result := Server(sLoadUnit, Me, uix, nodata^);
     923end;
     924
     925function TCustomAI.Unit_Unload(uix: Integer): Integer;
     926begin
     927  Result := Server(sUnloadUnit, Me, uix, nodata^);
     928end;
     929
     930function TCustomAI.Unit_AddToCity(uix: Integer): Integer;
     931begin
     932  Result := Server(sAddToCity, Me, uix, nodata^);
     933end;
     934
     935function TCustomAI.Unit_SelectTransport(uix: Integer): Integer;
     936begin
     937  Result := Server(sSelectTransport, Me, uix, nodata^);
     938end;
     939
     940
     941procedure TCustomAI.City_FindMyCity(Loc: Integer; var cix: Integer);
    942942begin
    943943  if Map[Loc] and (fCity or fOwned) <> fCity or fOwned then
     
    951951end;
    952952
    953 procedure TCustomAI.City_FindEnemyCity(Loc: integer; var ecix: integer);
     953procedure TCustomAI.City_FindEnemyCity(Loc: Integer; var ecix: Integer);
    954954begin
    955955  if Map[Loc] and (fCity or fOwned) <> fCity then
     
    963963end;
    964964
    965 function TCustomAI.City_HasProject(cix: integer): boolean;
     965function TCustomAI.City_HasProject(cix: Integer): Boolean;
    966966begin
    967967  Result := MyCity[cix].Project and (cpImp + cpIndex) <> cpImp + imTrGoods;
    968968end;
    969969
    970 function TCustomAI.City_CurrentImprovementProject(cix: integer): integer;
     970function TCustomAI.City_CurrentImprovementProject(cix: Integer): Integer;
    971971begin
    972972  if MyCity[cix].Project and cpImp = 0 then
     
    980980end;
    981981
    982 function TCustomAI.City_CurrentUnitProject(cix: integer): integer;
     982function TCustomAI.City_CurrentUnitProject(cix: Integer): Integer;
    983983begin
    984984  if MyCity[cix].Project and cpImp <> 0 then
     
    988988end;
    989989
    990 function TCustomAI.City_GetTileInfo(cix, TileLoc: integer;
    991   var TileInfo: TTileInfo): integer;
     990function TCustomAI.City_GetTileInfo(cix, TileLoc: Integer;
     991  var TileInfo: TTileInfo): Integer;
    992992begin
    993993  TileInfo.ExplCity := cix;
    994   Result := Server(sGetHypoCityTileInfo, me, TileLoc, TileInfo);
    995 end;
    996 
    997 function TCustomAI.City_GetReport(cix: integer; var Report: TCityReport): integer;
     994  Result := Server(sGetHypoCityTileInfo, Me, TileLoc, TileInfo);
     995end;
     996
     997function TCustomAI.City_GetReport(cix: Integer; var Report: TCityReport): Integer;
    998998begin
    999999  Report.HypoTiles := -1;
    10001000  Report.HypoTax := -1;
    10011001  Report.HypoLux := -1;
    1002   Result := Server(sGetCityReport, me, cix, Report);
    1003 end;
    1004 
    1005 function TCustomAI.City_GetHypoReport(cix, HypoTiles, HypoTax, HypoLux: integer;
    1006   var Report: TCityReport): integer;
     1002  Result := Server(sGetCityReport, Me, cix, Report);
     1003end;
     1004
     1005function TCustomAI.City_GetHypoReport(cix, HypoTiles, HypoTax, HypoLux: Integer;
     1006  var Report: TCityReport): Integer;
    10071007begin
    10081008  Report.HypoTiles := HypoTiles;
    10091009  Report.HypoTax := HypoTax;
    10101010  Report.HypoLux := HypoLux;
    1011   Result := Server(sGetCityReport, me, cix, Report);
    1012 end;
    1013 
    1014 function TCustomAI.City_GetReportNew(cix: integer; var Report: TCityReportNew): integer;
     1011  Result := Server(sGetCityReport, Me, cix, Report);
     1012end;
     1013
     1014function TCustomAI.City_GetReportNew(cix: Integer; var Report: TCityReportNew): Integer;
    10151015begin
    10161016  Report.HypoTiles := -1;
    10171017  Report.HypoTaxRate := -1;
    10181018  Report.HypoLuxuryRate := -1;
    1019   Result := Server(sGetCityReportNew, me, cix, Report);
     1019  Result := Server(sGetCityReportNew, Me, cix, Report);
    10201020end;
    10211021
    10221022function TCustomAI.City_GetHypoReportNew(cix, HypoTiles, HypoTaxRate,
    1023   HypoLuxuryRate: integer; var Report: TCityReportNew): integer;
     1023  HypoLuxuryRate: Integer; var Report: TCityReportNew): Integer;
    10241024begin
    10251025  Report.HypoTiles := HypoTiles;
    10261026  Report.HypoTaxRate := HypoTaxRate;
    10271027  Report.HypoLuxuryRate := HypoLuxuryRate;
    1028   Result := Server(sGetCityReportNew, me, cix, Report);
    1029 end;
    1030 
    1031 function TCustomAI.City_GetAreaInfo(cix: integer; var AreaInfo: TCityAreaInfo): integer;
    1032 begin
    1033   Result := Server(sGetCityAreaInfo, me, cix, AreaInfo);
    1034 end;
    1035 
    1036 function TCustomAI.City_StartUnitProduction(cix, mix: integer): integer;
     1028  Result := Server(sGetCityReportNew, Me, cix, Report);
     1029end;
     1030
     1031function TCustomAI.City_GetAreaInfo(cix: Integer; var AreaInfo: TCityAreaInfo): Integer;
     1032begin
     1033  Result := Server(sGetCityAreaInfo, Me, cix, AreaInfo);
     1034end;
     1035
     1036function TCustomAI.City_StartUnitProduction(cix, mix: Integer): Integer;
    10371037begin
    10381038  if (MyCity[cix].Project and (cpImp + cpIndex) <> mix) then
    10391039    // not already producing that
    1040     Result := Server(sSetCityProject, me, cix, mix);
    1041 end;
    1042 
    1043 function TCustomAI.City_StartEmigration(cix, mix: integer;
    1044   AllowDisbandCity, AsConscripts: boolean): integer;
    1045 var
    1046   NewProject: integer;
     1040    Result := Server(sSetCityProject, Me, cix, mix);
     1041end;
     1042
     1043function TCustomAI.City_StartEmigration(cix, mix: Integer;
     1044  AllowDisbandCity, AsConscripts: Boolean): Integer;
     1045var
     1046  NewProject: Integer;
    10471047begin
    10481048  NewProject := mix;
     
    10511051  if AsConscripts then
    10521052    NewProject := NewProject or cpConscripts;
    1053   Result := Server(sSetCityProject, me, cix, NewProject);
    1054 end;
    1055 
    1056 function TCustomAI.City_StartImprovement(cix, iix: integer): integer;
    1057 var
    1058   NewProject: integer;
     1053  Result := Server(sSetCityProject, Me, cix, NewProject);
     1054end;
     1055
     1056function TCustomAI.City_StartImprovement(cix, iix: Integer): Integer;
     1057var
     1058  NewProject: Integer;
    10591059begin
    10601060  NewProject := iix + cpImp;
    10611061  if (MyCity[cix].Project and (cpImp + cpIndex) <> NewProject) then
    10621062    // not already producing that
    1063     Result := Server(sSetCityProject, me, cix, NewProject);
    1064 end;
    1065 
    1066 function TCustomAI.City_Improvable(cix, iix: integer): boolean;
    1067 var
    1068   NewProject: integer;
     1063    Result := Server(sSetCityProject, Me, cix, NewProject);
     1064end;
     1065
     1066function TCustomAI.City_Improvable(cix, iix: Integer): Boolean;
     1067var
     1068  NewProject: Integer;
    10691069begin
    10701070  NewProject := iix + cpImp;
    1071   Result := Server(sSetCityProject - sExecute, me, cix, NewProject) >= rExecuted;
    1072 end;
    1073 
    1074 function TCustomAI.City_StopProduction(cix: integer): integer;
    1075 var
    1076   NewProject: integer;
     1071  Result := Server(sSetCityProject - sExecute, Me, cix, NewProject) >= rExecuted;
     1072end;
     1073
     1074function TCustomAI.City_StopProduction(cix: Integer): Integer;
     1075var
     1076  NewProject: Integer;
    10771077begin
    10781078  NewProject := imTrGoods + cpImp;
    1079   Result := Server(sSetCityProject, me, cix, NewProject);
    1080 end;
    1081 
    1082 function TCustomAI.City_BuyProject(cix: integer): integer;
    1083 begin
    1084   Result := Server(sBuyCityProject, me, cix, nodata^);
    1085 end;
    1086 
    1087 function TCustomAI.City_SellImprovement(cix, iix: integer): integer;
    1088 begin
    1089   Result := Server(sSellCityImprovement, me, cix, iix);
    1090 end;
    1091 
    1092 function TCustomAI.City_RebuildImprovement(cix, iix: integer): integer;
    1093 begin
    1094   Result := Server(sRebuildCityImprovement, me, cix, iix);
    1095 end;
    1096 
    1097 function TCustomAI.City_SetTiles(cix, NewTiles: integer): integer;
    1098 begin
    1099   Result := Server(sSetCityTiles, me, cix, NewTiles);
    1100 end;
    1101 
    1102 procedure TCustomAI.City_OptimizeTiles(cix: integer; ResourceWeights: cardinal);
     1079  Result := Server(sSetCityProject, Me, cix, NewProject);
     1080end;
     1081
     1082function TCustomAI.City_BuyProject(cix: Integer): Integer;
     1083begin
     1084  Result := Server(sBuyCityProject, Me, cix, nodata^);
     1085end;
     1086
     1087function TCustomAI.City_SellImprovement(cix, iix: Integer): Integer;
     1088begin
     1089  Result := Server(sSellCityImprovement, Me, cix, iix);
     1090end;
     1091
     1092function TCustomAI.City_RebuildImprovement(cix, iix: Integer): Integer;
     1093begin
     1094  Result := Server(sRebuildCityImprovement, Me, cix, iix);
     1095end;
     1096
     1097function TCustomAI.City_SetTiles(cix, NewTiles: Integer): Integer;
     1098begin
     1099  Result := Server(sSetCityTiles, Me, cix, NewTiles);
     1100end;
     1101
     1102procedure TCustomAI.City_OptimizeTiles(cix: Integer; ResourceWeights: Cardinal);
    11031103var
    11041104  Advice: TCityTileAdviceData;
    11051105begin
    11061106  Advice.ResourceWeights := ResourceWeights;
    1107   Server(sGetCityTileAdvice, me, cix, Advice);
     1107  Server(sGetCityTileAdvice, Me, cix, Advice);
    11081108  City_SetTiles(cix, Advice.Tiles);
    11091109end;
     
    11111111
    11121112// negotiation
    1113 function TCustomAI.Nego_CheckMyAction: integer;
    1114 begin
    1115   assert(Opponent >= 0); // only allowed in negotiation mode
    1116   assert((MyAction = scDipNotice) or (MyAction = scDipAccept) or
     1113function TCustomAI.Nego_CheckMyAction: Integer;
     1114begin
     1115  Assert(Opponent >= 0); // only allowed in negotiation mode
     1116  Assert((MyAction = scDipNotice) or (MyAction = scDipAccept) or
    11171117    (MyAction = scDipCancelTreaty) or (MyAction = scDipOffer) or (MyAction = scDipBreak));
    11181118  if MyAction = scDipOffer then
    1119     Result := Server(MyAction - sExecute, me, 0, MyOffer)
     1119    Result := Server(MyAction - sExecute, Me, 0, MyOffer)
    11201120  else
    1121     Result := Server(MyAction - sExecute, me, 0, nodata^);
     1121    Result := Server(MyAction - sExecute, Me, 0, nodata^);
    11221122end;
    11231123
    11241124
    11251125initialization
    1126   nodata := pointer(0);
     1126  nodata := Pointer(0);
    11271127  RWDataSize := 0;
    11281128
Note: See TracChangeset for help on using the changeset viewer.