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

Legend:

Unmodified
Added
Removed
  • branches/highdpi/AI/StdAI/CustomAI_Reload.pas

    r210 r465  
    1313TCustomAI=class
    1414public
    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
    2828protected
    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 DebugMessage(Level: integer; Text: string): boolean;
    63   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 DebugMessage(Level: Integer; Text: string): Boolean;
     63  function SetDebugMap(var DebugMap): Boolean;
    6464
    6565  // unit functions
    66   procedure Unit_FindMyDefender(Loc: integer; var uix: integer);
    67   procedure Unit_FindEnemyDefender(Loc: integer; var euix: integer);
    68   function Unit_Move(uix,ToLoc: integer): integer;
    69   function Unit_Step(uix,ToLoc: integer): integer;
    70   function Unit_Attack(uix,ToLoc: integer): integer;
    71   function Unit_DoMission(uix,MissionType,ToLoc: integer): integer;
    72   function Unit_MoveForecast(uix,ToLoc: integer; var RemainingMovement: integer): boolean;
    73   function Unit_AttackForecast(uix,ToLoc,AttackMovement: integer; var RemainingHealth: integer): boolean;
    74   function Unit_DefenseForecast(euix,ToLoc: integer; var RemainingHealth: integer): boolean;
    75   function Unit_Disband(uix: integer): integer;
    76   function Unit_StartJob(uix,NewJob: integer): integer;
    77   function Unit_SetHomeHere(uix: integer): integer;
    78   function Unit_Load(uix: integer): integer;
    79   function Unit_Unload(uix: integer): integer;
    80   function Unit_AddToCity(uix: integer): integer;
     66  procedure Unit_FindMyDefender(Loc: Integer; var uix: Integer);
     67  procedure Unit_FindEnemyDefender(Loc: Integer; var euix: Integer);
     68  function Unit_Move(uix,ToLoc: Integer): Integer;
     69  function Unit_Step(uix,ToLoc: Integer): Integer;
     70  function Unit_Attack(uix,ToLoc: Integer): Integer;
     71  function Unit_DoMission(uix,MissionType,ToLoc: Integer): Integer;
     72  function Unit_MoveForecast(uix,ToLoc: Integer; var RemainingMovement: Integer): Boolean;
     73  function Unit_AttackForecast(uix,ToLoc,AttackMovement: Integer; var RemainingHealth: Integer): Boolean;
     74  function Unit_DefenseForecast(euix,ToLoc: Integer; var RemainingHealth: Integer): Boolean;
     75  function Unit_Disband(uix: Integer): Integer;
     76  function Unit_StartJob(uix,NewJob: Integer): Integer;
     77  function Unit_SetHomeHere(uix: Integer): Integer;
     78  function Unit_Load(uix: Integer): Integer;
     79  function Unit_Unload(uix: Integer): Integer;
     80  function Unit_AddToCity(uix: Integer): Integer;
    8181
    8282  // city functions
    83   procedure City_FindMyCity(Loc: integer; var cix: integer);
    84   procedure City_FindEnemyCity(Loc: integer; var ecix: integer);
    85   function City_HasProject(cix: integer): boolean;
    86   function City_CurrentImprovementProject(cix: integer): integer;
    87   function City_CurrentUnitProject(cix: integer): integer;
    88   function City_GetTileInfo(cix,TileLoc: integer; var TileInfo: TTileInfo): integer;
    89   function City_GetReport(cix: integer; var Report: TCityReport): integer;
    90   function City_GetHypoReport(cix, HypoTiles, HypoTax, HypoLux: integer; var Report: TCityReport): integer;
    91   function City_GetAreaInfo(cix: integer; var AreaInfo: TCityAreaInfo): integer;
    92   function City_StartUnitProduction(cix,mix: integer): integer;
    93   function City_StartEmigration(cix,mix: integer; AllowDisbandCity, AsConscripts: boolean): integer;
    94   function City_StartImprovement(cix,iix: integer): integer;
    95   function City_Improvable(cix,iix: integer): boolean;
    96   function City_StopProduction(cix: integer): integer;
    97   function City_BuyProject(cix: integer): integer;
    98   function City_SellImprovement(cix,iix: integer): integer;
    99   function City_RebuildImprovement(cix,iix: integer): integer;
    100   function City_SetTiles(cix,NewTiles: integer): integer;
     83  procedure City_FindMyCity(Loc: Integer; var cix: Integer);
     84  procedure City_FindEnemyCity(Loc: Integer; var ecix: Integer);
     85  function City_HasProject(cix: Integer): Boolean;
     86  function City_CurrentImprovementProject(cix: Integer): Integer;
     87  function City_CurrentUnitProject(cix: Integer): Integer;
     88  function City_GetTileInfo(cix,TileLoc: Integer; var TileInfo: TTileInfo): Integer;
     89  function City_GetReport(cix: Integer; var Report: TCityReport): Integer;
     90  function City_GetHypoReport(cix, HypoTiles, HypoTax, HypoLux: Integer; var Report: TCityReport): Integer;
     91  function City_GetAreaInfo(cix: Integer; var AreaInfo: TCityAreaInfo): Integer;
     92  function City_StartUnitProduction(cix,mix: Integer): Integer;
     93  function City_StartEmigration(cix,mix: Integer; AllowDisbandCity, AsConscripts: Boolean): Integer;
     94  function City_StartImprovement(cix,iix: Integer): Integer;
     95  function City_Improvable(cix,iix: Integer): Boolean;
     96  function City_StopProduction(cix: Integer): Integer;
     97  function City_BuyProject(cix: Integer): Integer;
     98  function City_SellImprovement(cix,iix: Integer): Integer;
     99  function City_RebuildImprovement(cix,iix: Integer): Integer;
     100  function City_SetTiles(cix,NewTiles: Integer): Integer;
    101101
    102102  // negotiation
    103   function Nego_CheckMyAction: integer;
     103  function Nego_CheckMyAction: Integer;
    104104
    105105private
    106   HaveTurned: boolean;
     106  HaveTurned: Boolean;
    107107  UnwantedNego: set of 0..nPl-1;
    108108  Contacted: set of 0..nPl-1;
     
    114114Server: TServerCall;
    115115G: TNewGameData;
    116 RWDataSize, MapSize: integer;
    117 decompose24: cardinal;
    118 nodata: pointer;
     116RWDataSize, MapSize: Integer;
     117decompose24: Cardinal;
     118nodata: Pointer;
    119119
    120120const
     
    126126
    127127type
    128 TVicinity8Loc=array[0..7] of integer;
    129 TVicinity21Loc=array[0..27] of integer;
     128TVicinity8Loc=array[0..7] of Integer;
     129TVicinity21Loc=array[0..27] of Integer;
    130130
    131131
    132132procedure Init(NewGameData: TNewGameData);
    133133
    134 procedure ab_to_Loc(Loc0,a,b: integer; var Loc: integer);
    135 procedure Loc_to_ab(Loc0,Loc: integer; var a,b: integer);
    136 procedure ab_to_V8(a,b: integer; var V8: integer);
    137 procedure V8_to_ab(V8: integer; var a,b: integer);
    138 procedure ab_to_V21(a,b: integer; var V21: integer);
    139 procedure V21_to_ab(V21: integer; var a,b: integer);
    140 procedure V8_to_Loc(Loc0: integer; var VicinityLoc: TVicinity8Loc);
    141 procedure V21_to_Loc(Loc0: integer; var VicinityLoc: TVicinity21Loc);
     134procedure ab_to_Loc(Loc0,A,B: Integer; var Loc: Integer);
     135procedure Loc_to_ab(Loc0,Loc: Integer; var A,B: Integer);
     136procedure ab_to_V8(A,B: Integer; var V8: Integer);
     137procedure V8_to_ab(V8: Integer; var A,B: Integer);
     138procedure ab_to_V21(A,B: Integer; var V21: Integer);
     139procedure V21_to_ab(V21: Integer; var A,B: Integer);
     140procedure V8_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity8Loc);
     141procedure V21_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity21Loc);
    142142
    143143
     
    145145
    146146const
    147 ab_v8: array[-4..4] of integer = (5,6,7,4,-1,0,3,2,1);
    148 v8_a: array[0..7] of integer = (1,1,0,-1,-1,-1,0,1);
    149 v8_b: array[0..7] of integer = (0,1,1,1,0,-1,-1,-1);
    150 
    151 
    152 procedure ab_to_Loc(Loc0,a,b: integer; var Loc: integer);
     147ab_v8: array[-4..4] of Integer = (5,6,7,4,-1,0,3,2,1);
     148v8_a: array[0..7] of Integer = (1,1,0,-1,-1,-1,0,1);
     149v8_b: array[0..7] of Integer = (0,1,1,1,0,-1,-1,-1);
     150
     151
     152procedure ab_to_Loc(Loc0,A,B: Integer; var Loc: Integer);
    153153{relative location from Loc0}
    154154var
    155 y0: integer;
    156 begin
    157 assert((Loc0>=0) and (Loc0<MapSize) and (a-b+G.lx>=0));
    158 y0:=cardinal(Loc0)*decompose24 shr 24;
    159 Loc:=(Loc0+(a-b+y0 and 1+G.lx+G.lx) shr 1) mod G.lx +G.lx*(y0+a+b);
     155y0: Integer;
     156begin
     157Assert((Loc0>=0) and (Loc0<MapSize) and (A-B+G.lx>=0));
     158y0:=Cardinal(Loc0)*decompose24 shr 24;
     159Loc:=(Loc0+(A-B+y0 and 1+G.lx+G.lx) shr 1) mod G.lx +G.lx*(y0+A+B);
    160160if Loc>=MapSize then Loc:=-$1000
    161161end;
    162162
    163 procedure Loc_to_ab(Loc0,Loc: integer; var a,b: integer);
     163procedure Loc_to_ab(Loc0,Loc: Integer; var A,B: Integer);
    164164{$IFDEF FPC} // freepascal
    165165var
    166 dx,dy: integer;
     166dx,dy: Integer;
    167167begin
    168168dx:=((Loc mod G.lx *2 +Loc div G.lx and 1)
    169169  -(Loc0 mod G.lx *2 +Loc0 div G.lx and 1)+3*G.lx) mod (2*G.lx) -G.lx;
    170170dy:=Loc div G.lx-Loc0 div G.lx;
    171 a:=(dx+dy) div 2;
    172 b:=(dy-dx) div 2;
     171A:=(dx+dy) div 2;
     172B:=(dy-dx) div 2;
    173173end;
    174174{$ELSE} // delphi
     
    179179// calculate
    180180push ecx
    181 div byte ptr [G]
     181div Byte ptr [G]
    182182xor ebx,ebx
    183183mov bl,ah  // ebx:=Loc0 mod G.lx
     
    185185and ecx,$000000FF // ecx:=Loc0 div G.lx
    186186mov eax,edx
    187 div byte ptr [G]
     187div Byte ptr [G]
    188188xor edx,edx
    189189mov dl,ah // edx:=Loc mod G.lx
     
    202202mov edx,dword ptr [G]
    203203cmp eax,edx
    204 jl @a
     204jl @A
    205205  sub eax,edx
    206206  sub eax,edx
    207207  jmp @ok
    208 @a:
     208@A:
    209209neg edx
    210210cmp eax,edx
     
    219219add eax,ebx
    220220sar edx,1 // edx:=b
    221 mov ebx,[b]
     221mov ebx,[B]
    222222mov [ebx],edx
    223223sar eax,1 // eax:=a
    224 mov [a],eax
     224mov [A],eax
    225225
    226226pop ebx
     
    228228{$ENDIF}
    229229
    230 procedure ab_to_V8(a,b: integer; var V8: integer);
    231 begin
    232 assert((abs(a)<=1) and (abs(b)<=1) and ((a<>0) or (b<>0)));
    233 V8:=ab_v8[2*b+b+a];
    234 end;
    235 
    236 procedure V8_to_ab(V8: integer; var a,b: integer);
    237 begin
    238 a:=v8_a[V8]; b:=V8_b[V8];
    239 end;
    240 
    241 procedure ab_to_V21(a,b: integer; var V21: integer);
    242 begin
    243 V21:=(a+b+3) shl 2+(a-b+3) shr 1;
    244 end;
    245 
    246 procedure V21_to_ab(V21: integer; var a,b: integer);
    247 var
    248 dx,dy: integer;
     230procedure ab_to_V8(A,B: Integer; var V8: Integer);
     231begin
     232Assert((abs(A)<=1) and (abs(B)<=1) and ((A<>0) or (B<>0)));
     233V8:=ab_v8[2*B+B+A];
     234end;
     235
     236procedure V8_to_ab(V8: Integer; var A,B: Integer);
     237begin
     238A:=v8_a[V8]; B:=V8_b[V8];
     239end;
     240
     241procedure ab_to_V21(A,B: Integer; var V21: Integer);
     242begin
     243V21:=(A+B+3) shl 2+(A-B+3) shr 1;
     244end;
     245
     246procedure V21_to_ab(V21: Integer; var A,B: Integer);
     247var
     248dx,dy: Integer;
    249249begin
    250250dy:=V21 shr 2-3;
    251251dx:=V21 and 3 shl 1 -3 + (dy+3) and 1;
    252 a:=(dx+dy) div 2;
    253 b:=(dy-dx) div 2;
    254 end;
    255 
    256 procedure V8_to_Loc(Loc0: integer; var VicinityLoc: TVicinity8Loc);
    257 var
    258 x0,y0,lx: integer;
     252A:=(dx+dy) div 2;
     253B:=(dy-dx) div 2;
     254end;
     255
     256procedure V8_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity8Loc);
     257var
     258x0,y0,lx: Integer;
    259259begin
    260260lx:=G.lx;
    261 y0:=cardinal(Loc0)*decompose24 shr 24;
     261y0:=Cardinal(Loc0)*decompose24 shr 24;
    262262x0:=Loc0-y0*lx; // Loc0 mod lx;
    263263VicinityLoc[1]:=Loc0+lx*2;
     
    265265VicinityLoc[5]:=Loc0-lx*2;
    266266VicinityLoc[7]:=Loc0+1;
    267 inc(Loc0,y0 and 1);
     267Inc(Loc0,y0 and 1);
    268268VicinityLoc[0]:=Loc0+lx;
    269269VicinityLoc[2]:=Loc0+lx-1;
     
    276276  if x0=0 then
    277277    begin
    278     inc(VicinityLoc[3],lx);
     278    Inc(VicinityLoc[3],lx);
    279279    if y0 and 1=0 then
    280280      begin
    281       inc(VicinityLoc[2],lx);
    282       inc(VicinityLoc[4],lx);
     281      Inc(VicinityLoc[2],lx);
     282      Inc(VicinityLoc[4],lx);
    283283      end
    284284    end
     
    286286else
    287287  begin
    288   dec(VicinityLoc[7],lx);
     288  Dec(VicinityLoc[7],lx);
    289289  if y0 and 1=1 then
    290290    begin
    291     dec(VicinityLoc[0],lx);
    292     dec(VicinityLoc[6],lx);
     291    Dec(VicinityLoc[0],lx);
     292    Dec(VicinityLoc[6],lx);
    293293    end
    294294  end;
     
    306306end;
    307307
    308 procedure V21_to_Loc(Loc0: integer; var VicinityLoc: TVicinity21Loc);
    309 var
    310 dx,dy,bit,y0,xComp,yComp,xComp0,xCompSwitch: integer;
    311 dst: ^integer;
    312 begin
    313 y0:=cardinal(Loc0)*decompose24 shr 24;
     308procedure V21_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity21Loc);
     309var
     310dx,dy,bit,y0,xComp,yComp,xComp0,xCompSwitch: Integer;
     311dst: ^Integer;
     312begin
     313y0:=Cardinal(Loc0)*decompose24 shr 24;
    314314xComp0:=Loc0-y0*G.lx-1; // Loc0 mod G.lx -1
    315315xCompSwitch:=xComp0-1+y0 and 1;
    316 if xComp0<0 then inc(xComp0,G.lx);
    317 if xCompSwitch<0 then inc(xCompSwitch,G.lx);
     316if xComp0<0 then Inc(xComp0,G.lx);
     317if xCompSwitch<0 then Inc(xCompSwitch,G.lx);
    318318xCompSwitch:=xCompSwitch xor xComp0;
    319319yComp:=G.lx*(y0-3);
     
    329329      if bit and $67F7F76<>0 then dst^:=xComp+yComp
    330330      else dst^:=-1;
    331       inc(xComp);
    332       if xComp>=G.lx then dec(xComp, G.lx);
    333       inc(dst);
     331      Inc(xComp);
     332      if xComp>=G.lx then Dec(xComp, G.lx);
     333      Inc(dst);
    334334      bit:=bit shl 1;
    335335      end;
    336     inc(yComp,G.lx);
     336    Inc(yComp,G.lx);
    337337    end
    338338  else
    339339    begin
    340340    for dx:=0 to 3 do
    341       begin dst^:=-$1000; inc(dst); end;
     341      begin dst^:=-$1000; Inc(dst); end;
    342342    end
    343343end;
     
    345345
    346346procedure Init(NewGameData: TNewGameData);
    347 {$IFDEF DEBUG}var Loc: integer;{$ENDIF}
     347{$IFDEF DEBUG}var Loc: Integer;{$ENDIF}
    348348begin
    349349G:=NewGameData;
    350350MapSize:=G.lx*G.ly;
    351351decompose24:=(1 shl 24-1) div G.lx +1;
    352 {$IFDEF DEBUG}for Loc:=0 to MapSize-1 do assert(cardinal(Loc)*decompose24 shr 24=cardinal(Loc div G.lx));{$ENDIF}
    353 end;
    354 
    355 
    356 constructor TCustomAI.Create(Nation: integer);
     352{$IFDEF DEBUG}for Loc:=0 to MapSize-1 do Assert(Cardinal(Loc)*decompose24 shr 24=Cardinal(Loc div G.lx));{$ENDIF}
     353end;
     354
     355
     356constructor TCustomAI.Create(Nation: Integer);
    357357begin
    358358inherited Create;
    359 me:=Nation;
    360 RO:=pointer(G.RO[Nation]);
    361 Map:=pointer(RO.Map);
    362 MyUnit:=pointer(RO.Un);
    363 MyCity:=pointer(RO.City);
    364 MyModel:=pointer(RO.Model);
     359Me:=Nation;
     360RO:=Pointer(G.RO[Nation]);
     361Map:=Pointer(RO.Map);
     362MyUnit:=Pointer(RO.Un);
     363MyCity:=Pointer(RO.City);
     364MyModel:=Pointer(RO.Model);
    365365Opponent:=-1;
    366366end;
     
    368368destructor TCustomAI.Destroy;
    369369begin
    370 Server(sSetDebugMap,me,0,nodata^);
    371 end;
    372 
    373 
    374 procedure TCustomAI.Process(Command: integer; var Data);
    375 var
    376 Nation,NewResearch,NewGov,count,ad,cix,iix: integer;
     370Server(sSetDebugMap,Me,0,nodata^);
     371end;
     372
     373
     374procedure TCustomAI.Process(Command: Integer; var Data);
     375var
     376Nation,NewResearch,NewGov,count,ad,cix,iix: Integer;
    377377NegoTime: TNegoTime;
    378378begin
     
    380380  cTurn, cContinue:
    381381    begin
    382     if RO.Alive and (1 shl me)=0 then
     382    if RO.Alive and (1 shl Me)=0 then
    383383      begin // I'm dead, huhu
    384       Server(sTurn,me,0,nodata^);
    385       exit
     384      Server(sTurn,Me,0,nodata^);
     385      Exit
    386386      end;
    387387    if Command=cTurn then
    388388      begin
    389       fillchar(cixStateImp, sizeof(cixStateImp), $FF);
     389      FillChar(cixStateImp, SizeOf(cixStateImp), $FF);
    390390      for cix:=0 to RO.nCity-1 do if MyCity[cix].Loc>=0 then
    391391        for iix:=imPalace to imSpacePort do
     
    396396        NewGov:=ChooseGovernment;
    397397        if NewGov>gAnarchy then
    398           Server(sSetGovernment,me,NewGov,nodata^);
     398          Server(sSetGovernment,Me,NewGov,nodata^);
    399399        end;
    400       HaveTurned:=false;
     400      HaveTurned:=False;
    401401      Contacted:=[];
    402402      end;
     
    405405      if OnNegoRejected_CancelTreaty then
    406406        if RO.Treaty[Opponent]>=trPeace then
    407           if Server(sCancelTreaty,me,0,nodata^)<rExecuted then
    408             assert(false)
     407          if Server(sCancelTreaty,Me,0,nodata^)<rExecuted then
     408            Assert(False)
    409409      end
    410410    else UnwantedNego:=[];
     
    415415      if RO.Government<>gAnarchy then
    416416        for Nation:=0 to nPl-1 do
    417            if (Nation<>me) and (1 shl Nation and RO.Alive<>0)
     417           if (Nation<>Me) and (1 shl Nation and RO.Alive<>0)
    418418             and (RO.Treaty[Nation]>=trNone)
    419419             and not (Nation in Contacted) and not (Nation in UnwantedNego)
    420              and (Server(scContact-sExecute + Nation shl 4, me, 0, nodata^)>=rExecuted) then
     420             and (Server(scContact-sExecute + Nation shl 4, Me, 0, nodata^)>=rExecuted) then
    421421             if WantNegotiation(Nation, NegoTime) then
    422422               begin
    423                if Server(scContact + Nation shl 4, me, 0, nodata^)>=rExecuted then
     423               if Server(scContact + Nation shl 4, Me, 0, nodata^)>=rExecuted then
    424424                 begin
    425                  include(Contacted, Nation);
     425                 Include(Contacted, Nation);
    426426                 Opponent:=Nation;
    427427                 MyAction:=scContact;
    428                  exit;
     428                 Exit;
    429429                 end;
    430430               end
    431              else include(UnwantedNego,Nation);
     431             else Include(UnwantedNego,Nation);
    432432      if NegoTime=BeginOfTurn then
    433433        begin
    434434        DoTurn;
    435         HaveTurned:=true;
     435        HaveTurned:=True;
    436436        Contacted:=[];
    437437        UnwantedNego:=[];
    438438        end
    439       else break;
    440     until false;
     439      else Break;
     440    until False;
    441441    if RO.Happened and phTech<>0 then
    442442      begin
     
    446446        count:=0;
    447447        for ad:=0 to nAdv-1 do if AdvanceResearchable(ad) then
    448           begin inc(count); if random(count)=0 then NewResearch:=ad end
     448          begin Inc(count); if random(count)=0 then NewResearch:=ad end
    449449        end;
    450       Server(sSetResearch,me,NewResearch,nodata^)
     450      Server(sSetResearch,Me,NewResearch,nodata^)
    451451      end;
    452     if (me=1) and (RO.Turn=800) then
     452    if (Me=1) and (RO.Turn=800) then
    453453      begin
    454454      count:=0;
    455       Server(sReload,me,0,count)
     455      Server(sReload,Me,0,count)
    456456      end
    457457    else if (RO.Turn>10) and (random(1000)=0) then
    458458      begin
    459459      count:=RO.Turn-10;
    460       Server(sReload,me,0,count)
     460      Server(sReload,Me,0,count)
    461461      end
    462     else if Server(sTurn,me,0,nodata^)<rExecuted then
    463       assert(false);
     462    else if Server(sTurn,Me,0,nodata^)<rExecuted then
     463      Assert(False);
    464464    end;
    465465  scContact:
    466     if WantNegotiation(integer(Data), EnemyCalled) then
     466    if WantNegotiation(Integer(Data), EnemyCalled) then
    467467      begin
    468       if Server(scDipStart, me, 0, nodata^)<rExecuted then
    469         assert(false);
    470       Opponent:=integer(Data);
     468      if Server(scDipStart, Me, 0, nodata^)<rExecuted then
     469        Assert(False);
     470      Opponent:=Integer(Data);
    471471      MyAction:=scDipStart;
    472472      end
    473473    else
    474474      begin
    475       if Server(scReject, me, 0, nodata^)<rExecuted then
    476         assert(false);
     475      if Server(scReject, Me, 0, nodata^)<rExecuted then
     476        Assert(False);
    477477      end;
    478478  scDipStart, scDipNotice, scDipAccept, scDipCancelTreaty, scDipOffer, scDipBreak:
     
    486486    else begin MyAction:=scDipOffer; MyOffer.nDeliver:=0; MyOffer.nCost:=0; end;
    487487    DoNegotiation;
    488     assert((MyAction=scDipNotice) or (MyAction=scDipAccept)
     488    Assert((MyAction=scDipNotice) or (MyAction=scDipAccept)
    489489      or (MyAction=scDipCancelTreaty) or (MyAction=scDipOffer)
    490490      or (MyAction=scDipBreak));
    491     if MyAction=scDipOffer then Server(MyAction, me, 0, MyOffer)
    492     else Server(MyAction, me, 0, nodata^);
     491    if MyAction=scDipOffer then Server(MyAction, Me, 0, MyOffer)
     492    else Server(MyAction, Me, 0, nodata^);
    493493    end;
    494494  cShowEndContact:
     
    515515
    516516procedure TCustomAI.OnBeforeEnemyAttack(UnitInfo: TUnitInfo; ToLoc, EndHealth,
    517   EndHealthDef: integer);
    518 begin
    519 end;
    520 
    521 procedure TCustomAI.OnBeforeEnemyCapture(UnitInfo: TUnitInfo; ToLoc: integer);
     517  EndHealthDef: Integer);
     518begin
     519end;
     520
     521procedure TCustomAI.OnBeforeEnemyCapture(UnitInfo: TUnitInfo; ToLoc: Integer);
    522522begin
    523523end;
     
    531531end;
    532532
    533 function TCustomAI.ChooseResearchAdvance: integer;
    534 begin
    535 result:=-1
    536 end;
    537 
    538 function TCustomAI.ChooseStealAdvance: integer;
    539 begin
    540 result:=-1
    541 end;
    542 
    543 function TCustomAI.ChooseGovernment: integer;
    544 begin
    545 result:=gDespotism
    546 end;
    547 
    548 function TCustomAI.WantNegotiation(Nation: integer; NegoTime: TNegoTime): boolean;
    549 begin
    550 result:=false;
    551 end;
    552 
    553 function TCustomAI.OnNegoRejected_CancelTreaty: boolean;
    554 begin
    555 result:=false;
     533function TCustomAI.ChooseResearchAdvance: Integer;
     534begin
     535Result:=-1
     536end;
     537
     538function TCustomAI.ChooseStealAdvance: Integer;
     539begin
     540Result:=-1
     541end;
     542
     543function TCustomAI.ChooseGovernment: Integer;
     544begin
     545Result:=gDespotism
     546end;
     547
     548function TCustomAI.WantNegotiation(Nation: Integer; NegoTime: TNegoTime): Boolean;
     549begin
     550Result:=False;
     551end;
     552
     553function TCustomAI.OnNegoRejected_CancelTreaty: Boolean;
     554begin
     555Result:=False;
    556556end;
    557557{$HINTS ON}
     
    559559procedure TCustomAI.StealAdvance;
    560560var
    561 Steal, ad, count: integer;
     561Steal, ad, count: Integer;
    562562begin
    563563Steal:=ChooseStealAdvance;
     
    566566  count:=0;
    567567  for ad:=0 to nAdv-1 do if AdvanceStealable(ad) then
    568     begin inc(count); if random(count)=0 then Steal:=ad end
     568    begin Inc(count); if random(count)=0 then Steal:=ad end
    569569  end;
    570 if Steal>=0 then Server(sStealTech,me,Steal,nodata^);
     570if Steal>=0 then Server(sStealTech,Me,Steal,nodata^);
    571571RO.Happened:=RO.Happened and not phStealTech
    572572end;
    573573
    574 function TCustomAI.IsResearched(Advance: integer): boolean;
    575 begin
    576 result:= RO.Tech[Advance]>=tsApplicable
    577 end;
    578 
    579 function TCustomAI.ResearchCost: integer;
    580 begin
    581 Server(sGetTechCost,me,0,result)
    582 end;
    583 
    584 function TCustomAI.ChangeAttitude(Nation, Attitude: integer): integer;
    585 begin
    586 result:=Server(sSetAttitude+Nation shl 4,me,Attitude,nodata^)
    587 end;
    588 
    589 function TCustomAI.Revolution: integer;
    590 begin
    591 result:=Server(sRevolution,me,0,nodata^);
    592 end;
    593 
    594 function TCustomAI.ChangeRates(Tax,Lux: integer): integer;
    595 begin
    596 result:=Server(sSetRates,me,Tax div 10 and $f+Lux div 10 and $f shl 4,nodata^)
    597 end;
    598 
    599 function TCustomAI.PrepareNewModel(Domain: integer): integer;
    600 begin
    601 result:=Server(sCreateDevModel,me,Domain,nodata^);
    602 end;
    603 
    604 function TCustomAI.SetNewModelFeature(F, Count: integer): integer;
    605 begin
    606 result:=Server(sSetDevModelCap+Count shl 4,me,F,nodata^)
    607 end;
    608 
    609 function TCustomAI.AdvanceResearchable(Advance: integer): boolean;
    610 begin
    611 result:= Server(sSetResearch-sExecute,me,Advance,nodata^)>=rExecuted;
    612 end;
    613 
    614 function TCustomAI.AdvanceStealable(Advance: integer): boolean;
    615 begin
    616 result:= Server(sStealTech-sExecute,me,Advance,nodata^)>=rExecuted;
    617 end;
    618 
    619 function TCustomAI.DebugMessage(Level: integer; Text: string): boolean;
    620 begin
    621 Text:=copy('P'+char(48+me)+' '+Text,1,254);
    622 Server(sMessage,me,Level,pchar(Text)^);
    623 
    624 result:=true;
     574function TCustomAI.IsResearched(Advance: Integer): Boolean;
     575begin
     576Result:= RO.Tech[Advance]>=tsApplicable
     577end;
     578
     579function TCustomAI.ResearchCost: Integer;
     580begin
     581Server(sGetTechCost,Me,0,Result)
     582end;
     583
     584function TCustomAI.ChangeAttitude(Nation, Attitude: Integer): Integer;
     585begin
     586Result:=Server(sSetAttitude+Nation shl 4,Me,Attitude,nodata^)
     587end;
     588
     589function TCustomAI.Revolution: Integer;
     590begin
     591Result:=Server(sRevolution,Me,0,nodata^);
     592end;
     593
     594function TCustomAI.ChangeRates(Tax,Lux: Integer): Integer;
     595begin
     596Result:=Server(sSetRates,Me,Tax div 10 and $F+Lux div 10 and $F shl 4,nodata^)
     597end;
     598
     599function TCustomAI.PrepareNewModel(Domain: Integer): Integer;
     600begin
     601Result:=Server(sCreateDevModel,Me,Domain,nodata^);
     602end;
     603
     604function TCustomAI.SetNewModelFeature(F, Count: Integer): Integer;
     605begin
     606Result:=Server(sSetDevModelCap+Count shl 4,Me,F,nodata^)
     607end;
     608
     609function TCustomAI.AdvanceResearchable(Advance: Integer): Boolean;
     610begin
     611Result:= Server(sSetResearch-sExecute,Me,Advance,nodata^)>=rExecuted;
     612end;
     613
     614function TCustomAI.AdvanceStealable(Advance: Integer): Boolean;
     615begin
     616Result:= Server(sStealTech-sExecute,Me,Advance,nodata^)>=rExecuted;
     617end;
     618
     619function TCustomAI.DebugMessage(Level: Integer; Text: string): Boolean;
     620begin
     621Text:=Copy('P'+char(48+Me)+' '+Text,1,254);
     622Server(sMessage,Me,Level,PChar(Text)^);
     623
     624Result:=True;
    625625  // always returns true so that it can be used like
    626626  // "assert(DebugMessage(...));" -> not compiled in release build
    627627end;
    628628
    629 function TCustomAI.SetDebugMap(var DebugMap): boolean;
    630 begin
    631 Server(sSetDebugMap, me, 0, DebugMap);
    632 
    633 result:=true;
     629function TCustomAI.SetDebugMap(var DebugMap): Boolean;
     630begin
     631Server(sSetDebugMap, Me, 0, DebugMap);
     632
     633Result:=True;
    634634  // always returns true so that it can be used like
    635635  // "assert(SetDebugMap(...));" -> not compiled in release build
    636636end;
    637637
    638 procedure TCustomAI.Unit_FindMyDefender(Loc: integer; var uix: integer);
    639 begin
    640 if Server(sGetDefender,me,Loc,uix)<rExecuted then uix:=-1
    641 end;
    642 
    643 procedure TCustomAI.Unit_FindEnemyDefender(Loc: integer; var euix: integer);
     638procedure TCustomAI.Unit_FindMyDefender(Loc: Integer; var uix: Integer);
     639begin
     640if Server(sGetDefender,Me,Loc,uix)<rExecuted then uix:=-1
     641end;
     642
     643procedure TCustomAI.Unit_FindEnemyDefender(Loc: Integer; var euix: Integer);
    644644begin
    645645euix:=RO.nEnemyUn-1;
    646646while (euix>=0) and (RO.EnemyUn[euix].Loc<>Loc) do
    647   dec(euix);
    648 end;
    649 
    650 function TCustomAI.Unit_Move(uix,ToLoc: integer): integer;
    651 var
    652 Step: integer;
    653 DestinationReached: boolean;
     647  Dec(euix);
     648end;
     649
     650function TCustomAI.Unit_Move(uix,ToLoc: Integer): Integer;
     651var
     652Step: Integer;
     653DestinationReached: Boolean;
    654654Advice: TMoveAdviceData;
    655655begin
    656 assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0)); // is a unit
     656Assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0)); // is a unit
    657657{Loc_to_ab(MyUnit[uix].Loc,ToLoc,a,b);
    658 assert((a<>0) or (b<>0));
    659 if (a>=-1) and (a<=1) and (b>=-1) and (b<=1) then
     658Assert((A<>0) or (B<>0));
     659if (A>=-1) and (A<=1) and (B>=-1) and (B<=1) then
    660660  begin // move to adjacent tile
    661   !!!problem: if move is invalid, return codes are not consistent with other branch (eNoWay)
     661  !!!problem: if Move is invalid, return codes are not consistent with other branch (eNoWay)
    662662  Advice.nStep:=1;
    663   Advice.dx[0]:=a-b;
    664   Advice.dy[0]:=a+b;
     663  Advice.dx[0]:=A-B;
     664  Advice.dy[0]:=A+B;
    665665  Advice.MoreTurns:=0;
    666666  Advice.MaxHostile_MovementLeft:=MyUnit[uix].Movement;
    667   result:=eOK;
     667  Result:=eOK;
    668668  end
    669669else}
     
    672672  Advice.MoreTurns:=9999;
    673673  Advice.MaxHostile_MovementLeft:=100;
    674   result:=Server(sGetMoveAdvice,me,uix,Advice);
     674  Result:=Server(sGetMoveAdvice,Me,uix,Advice);
    675675  end;
    676 if result=eOk then
     676if Result=eOk then
    677677  begin
    678   DestinationReached:=false;
     678  DestinationReached:=False;
    679679  Step:=0;
    680680  repeat
    681     if result and (rExecuted or rUnitRemoved)=rExecuted then // check if destination reached
     681    if Result and (rExecuted or rUnitRemoved)=rExecuted then // check if destination reached
    682682      if (ToLoc>=0) and (Advice.MoreTurns=0) and (Step=Advice.nStep-1)
    683683        and ((Map[ToLoc] and (fUnit or fOwned)=fUnit) // attack
     
    685685          and ((MyModel[MyUnit[uix].mix].Domain<>dGround) // bombardment
    686686            or (MyModel[MyUnit[uix].mix].Flags and mdCivil<>0))) then // can't capture
    687         begin DestinationReached:=true; break end // stop next to destination
     687        begin DestinationReached:=True; Break end // stop next to destination
    688688      else if Step=Advice.nStep then
    689         DestinationReached:=true; // normal move -- stop at destination
    690 
    691     if (Step=Advice.nStep) or (result<>eOK) and (result<>eLoaded) then
    692       break;
    693 
    694     result:=Server(sMoveUnit+(Advice.dx[Step] and 7) shl 4 +(Advice.dy[Step] and 7) shl 7,
    695       me,uix,nodata^);
    696     inc(Step);
     689        DestinationReached:=True; // normal move -- stop at destination
     690
     691    if (Step=Advice.nStep) or (Result<>eOK) and (Result<>eLoaded) then
     692      Break;
     693
     694    Result:=Server(sMoveUnit+(Advice.dx[Step] and 7) shl 4 +(Advice.dy[Step] and 7) shl 7,
     695      Me,uix,nodata^);
     696    Inc(Step);
    697697    if RO.Happened and phStealTech<>0 then StealAdvance;
    698   until false;
     698  until False;
    699699  if DestinationReached then
    700700    if Advice.nStep=25 then
    701       result:=Unit_Move(uix,ToLoc) // Shinkansen
     701      Result:=Unit_Move(uix,ToLoc) // Shinkansen
    702702    else if Advice.MoreTurns=0 then
    703       result:=result or rLocationReached
    704     else result:=result or rMoreTurns;
    705   end
    706 end;
    707 
    708 function TCustomAI.Unit_Step(uix,ToLoc: integer): integer;
    709 var
    710 a,b: integer;
    711 begin
    712 Loc_to_ab(MyUnit[uix].Loc, ToLoc, a, b);
    713 assert(((a<>0) or (b<>0)) and (a>=-1) and (a<=1) and (b>=-1) and (b<=1));
    714 result:=Server(sMoveUnit+((a-b) and 7) shl 4 +((a+b) and 7) shl 7, me, uix, nodata^);
     703      Result:=Result or rLocationReached
     704    else Result:=Result or rMoreTurns;
     705  end
     706end;
     707
     708function TCustomAI.Unit_Step(uix,ToLoc: Integer): Integer;
     709var
     710A,B: Integer;
     711begin
     712Loc_to_ab(MyUnit[uix].Loc, ToLoc, A, B);
     713Assert(((A<>0) or (B<>0)) and (A>=-1) and (A<=1) and (B>=-1) and (B<=1));
     714Result:=Server(sMoveUnit+((A-B) and 7) shl 4 +((A+B) and 7) shl 7, Me, uix, nodata^);
    715715if RO.Happened and phStealTech<>0 then StealAdvance;
    716716end;
    717717
    718 function TCustomAI.Unit_Attack(uix,ToLoc: integer): integer;
    719 var
    720 a,b: integer;
    721 begin
    722 assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0) // is a unit
     718function TCustomAI.Unit_Attack(uix,ToLoc: Integer): Integer;
     719var
     720A,B: Integer;
     721begin
     722Assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0) // is a unit
    723723  and ((Map[ToLoc] and (fUnit or fOwned)=fUnit) // is an attack
    724724  or (Map[ToLoc] and (fCity or fOwned)=fCity)
    725725  and (MyModel[MyUnit[uix].mix].Domain<>dGround))); // is a bombardment
    726 Loc_to_ab(MyUnit[uix].Loc,ToLoc,a,b);
    727 assert(((a<>0) or (b<>0)) and (a>=-1) and (a<=1) and (b>=-1) and (b<=1)); // attack to adjacent tile
    728 result:=Server(sMoveUnit+(a-b) and 7 shl 4 +(a+b) and 7 shl 7,me,uix,nodata^);
    729 end;
    730 
    731 function TCustomAI.Unit_DoMission(uix,MissionType,ToLoc: integer): integer;
    732 var
    733 a,b: integer;
    734 begin
    735 result:=Server(sSetSpyMission + MissionType shl 4,me,0,nodata^);
    736 if result>=rExecuted then
     726Loc_to_ab(MyUnit[uix].Loc,ToLoc,A,B);
     727Assert(((A<>0) or (B<>0)) and (A>=-1) and (A<=1) and (B>=-1) and (B<=1)); // attack to adjacent tile
     728Result:=Server(sMoveUnit+(A-B) and 7 shl 4 +(A+B) and 7 shl 7,Me,uix,nodata^);
     729end;
     730
     731function TCustomAI.Unit_DoMission(uix,MissionType,ToLoc: Integer): Integer;
     732var
     733A,B: Integer;
     734begin
     735Result:=Server(sSetSpyMission + MissionType shl 4,Me,0,nodata^);
     736if Result>=rExecuted then
    737737  begin
    738   assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0) // is a unit
     738  Assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0) // is a unit
    739739    and (MyModel[MyUnit[uix].mix].Kind=mkDiplomat)); // is a commando
    740   Loc_to_ab(MyUnit[uix].Loc,ToLoc,a,b);
    741   assert(((a<>0) or (b<>0)) and (a>=-1) and (a<=1) and (b>=-1) and (b<=1)); // city must be adjacent
    742   result:=Server(sMoveUnit-sExecute+(a-b) and 7 shl 4 +(a+b) and 7 shl 7,me,uix,nodata^);
    743   if result=eMissionDone then
    744     result:=Server(sMoveUnit+(a-b) and 7 shl 4 +(a+b) and 7 shl 7,me,uix,nodata^)
    745   else if (result<>eNoTime_Move) and (result<>eTreaty) and (result<>eNoTurn) then
    746     result:=eInvalid // not a special commando mission!
    747   end
    748 end;
    749 
    750 function TCustomAI.Unit_MoveForecast(uix,ToLoc: integer;
    751   var RemainingMovement: integer): boolean;
     740  Loc_to_ab(MyUnit[uix].Loc,ToLoc,A,B);
     741  Assert(((A<>0) or (B<>0)) and (A>=-1) and (A<=1) and (B>=-1) and (B<=1)); // city must be adjacent
     742  Result:=Server(sMoveUnit-sExecute+(A-B) and 7 shl 4 +(A+B) and 7 shl 7,Me,uix,nodata^);
     743  if Result=eMissionDone then
     744    Result:=Server(sMoveUnit+(A-B) and 7 shl 4 +(A+B) and 7 shl 7,Me,uix,nodata^)
     745  else if (Result<>eNoTime_Move) and (Result<>eTreaty) and (Result<>eNoTurn) then
     746    Result:=eInvalid // not a special commando mission!
     747  end
     748end;
     749
     750function TCustomAI.Unit_MoveForecast(uix,ToLoc: Integer;
     751  var RemainingMovement: Integer): Boolean;
    752752var
    753753Advice: TMoveAdviceData;
    754754begin
    755 assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0)); // is a unit
     755Assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0)); // is a unit
    756756Advice.ToLoc:=ToLoc;
    757757Advice.MoreTurns:=0;
    758758Advice.MaxHostile_MovementLeft:=100;
    759 if Server(sGetMoveAdvice,me,uix,Advice)=eOk then
     759if Server(sGetMoveAdvice,Me,uix,Advice)=eOk then
    760760  begin
    761761  RemainingMovement:=Advice.MaxHostile_MovementLeft;
    762   result:=true
     762  Result:=True
    763763  end
    764764else
    765765  begin
    766766  RemainingMovement:=-1;
    767   result:=false
    768   end
    769 end;
    770 
    771 function TCustomAI.Unit_AttackForecast(uix,ToLoc,AttackMovement: integer;
    772   var RemainingHealth: integer): boolean;
     767  Result:=False
     768  end
     769end;
     770
     771function TCustomAI.Unit_AttackForecast(uix,ToLoc,AttackMovement: Integer;
     772  var RemainingHealth: Integer): Boolean;
    773773var
    774774BattleForecast: TBattleForecast;
    775775begin
    776 assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0) // is a unit
     776Assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0) // is a unit
    777777  and (Map[ToLoc] and (fUnit or fOwned)=fUnit)); // is an attack
    778778RemainingHealth:=-$100;
    779 result:=false;
     779Result:=False;
    780780if AttackMovement>=0 then with MyUnit[uix] do
    781781  begin
    782   BattleForecast.pAtt:=me;
     782  BattleForecast.pAtt:=Me;
    783783  BattleForecast.mixAtt:=mix;
    784784  BattleForecast.HealthAtt:=Health;
     
    786786  BattleForecast.FlagsAtt:=Flags;
    787787  BattleForecast.Movement:=AttackMovement;
    788   if Server(sGetBattleForecast,me,ToLoc,BattleForecast)>=rExecuted then
     788  if Server(sGetBattleForecast,Me,ToLoc,BattleForecast)>=rExecuted then
    789789    begin
    790790    if BattleForecast.EndHealthAtt>0 then
    791791      RemainingHealth:=BattleForecast.EndHealthAtt
    792792    else RemainingHealth:=-BattleForecast.EndHealthDef;
    793     result:=true
     793    Result:=True
    794794    end
    795795  end
    796796end;
    797797
    798 function TCustomAI.Unit_DefenseForecast(euix,ToLoc: integer;
    799   var RemainingHealth: integer): boolean;
     798function TCustomAI.Unit_DefenseForecast(euix,ToLoc: Integer;
     799  var RemainingHealth: Integer): Boolean;
    800800var
    801801BattleForecast: TBattleForecast;
    802802begin
    803 assert((euix>=0) and (euix<RO.nEnemyUn) and (RO.EnemyUn[euix].Loc>=0) // is an enemy unit
     803Assert((euix>=0) and (euix<RO.nEnemyUn) and (RO.EnemyUn[euix].Loc>=0) // is an enemy unit
    804804  and (Map[ToLoc] and (fUnit or fOwned)=(fUnit or fOwned))); // is an attack
    805805RemainingHealth:=$100;
    806 result:=false;
     806Result:=False;
    807807with RO.EnemyUn[euix] do
    808808  begin
     
    813813  BattleForecast.FlagsAtt:=Flags;
    814814  BattleForecast.Movement:=100;
    815   if Server(sGetBattleForecast,me,ToLoc,BattleForecast)>=rExecuted then
     815  if Server(sGetBattleForecast,Me,ToLoc,BattleForecast)>=rExecuted then
    816816    begin
    817817    if BattleForecast.EndHealthDef>0 then
    818818      RemainingHealth:=BattleForecast.EndHealthDef
    819819    else RemainingHealth:=-BattleForecast.EndHealthAtt;
    820     result:=true
     820    Result:=True
    821821    end
    822822  end
    823823end;
    824824
    825 function TCustomAI.Unit_Disband(uix: integer): integer;
    826 begin
    827 result:=Server(sRemoveUnit,me,uix,nodata^)
    828 end;
    829 
    830 function TCustomAI.Unit_StartJob(uix,NewJob: integer): integer;
    831 begin
    832 result:=Server(sStartJob+NewJob shl 4,me,uix,nodata^)
    833 end;
    834 
    835 function TCustomAI.Unit_SetHomeHere(uix: integer): integer;
    836 begin
    837 result:=Server(sSetUnitHome,me,uix,nodata^)
    838 end;
    839 
    840 function TCustomAI.Unit_Load(uix: integer): integer;
    841 begin
    842 result:=Server(sLoadUnit,me,uix,nodata^)
    843 end;
    844 
    845 function TCustomAI.Unit_Unload(uix: integer): integer;
    846 begin
    847 result:=Server(sUnloadUnit,me,uix,nodata^)
    848 end;
    849 
    850 function TCustomAI.Unit_AddToCity(uix: integer): integer;
    851 begin
    852 result:=Server(sAddToCity,me,uix,nodata^)
    853 end;
    854 
    855 
    856 procedure TCustomAI.City_FindMyCity(Loc: integer; var cix: integer);
     825function TCustomAI.Unit_Disband(uix: Integer): Integer;
     826begin
     827Result:=Server(sRemoveUnit,Me,uix,nodata^)
     828end;
     829
     830function TCustomAI.Unit_StartJob(uix,NewJob: Integer): Integer;
     831begin
     832Result:=Server(sStartJob+NewJob shl 4,Me,uix,nodata^)
     833end;
     834
     835function TCustomAI.Unit_SetHomeHere(uix: Integer): Integer;
     836begin
     837Result:=Server(sSetUnitHome,Me,uix,nodata^)
     838end;
     839
     840function TCustomAI.Unit_Load(uix: Integer): Integer;
     841begin
     842Result:=Server(sLoadUnit,Me,uix,nodata^)
     843end;
     844
     845function TCustomAI.Unit_Unload(uix: Integer): Integer;
     846begin
     847Result:=Server(sUnloadUnit,Me,uix,nodata^)
     848end;
     849
     850function TCustomAI.Unit_AddToCity(uix: Integer): Integer;
     851begin
     852Result:=Server(sAddToCity,Me,uix,nodata^)
     853end;
     854
     855
     856procedure TCustomAI.City_FindMyCity(Loc: Integer; var cix: Integer);
    857857begin
    858858if Map[Loc] and (fCity or fOwned)<>fCity or fOwned then
     
    862862  cix:=RO.nCity-1;
    863863  while (cix>=0) and (MyCity[cix].Loc<>Loc) do
    864     dec(cix);
    865   end
    866 end;
    867 
    868 procedure TCustomAI.City_FindEnemyCity(Loc: integer; var ecix: integer);
     864    Dec(cix);
     865  end
     866end;
     867
     868procedure TCustomAI.City_FindEnemyCity(Loc: Integer; var ecix: Integer);
    869869begin
    870870if Map[Loc] and (fCity or fOwned)<>fCity then
     
    874874  ecix:=RO.nEnemyCity-1;
    875875  while (ecix>=0) and (RO.EnemyCity[ecix].Loc<>Loc) do
    876     dec(ecix);
    877   end
    878 end;
    879 
    880 function TCustomAI.City_HasProject(cix: integer): boolean;
    881 begin
    882 result:= MyCity[cix].Project and (cpImp+cpIndex)<>cpImp+imTrGoods
    883 end;
    884 
    885 function TCustomAI.City_CurrentImprovementProject(cix: integer): integer;
    886 begin
    887 if MyCity[cix].Project and cpImp=0 then result:=-1
     876    Dec(ecix);
     877  end
     878end;
     879
     880function TCustomAI.City_HasProject(cix: Integer): Boolean;
     881begin
     882Result:= MyCity[cix].Project and (cpImp+cpIndex)<>cpImp+imTrGoods
     883end;
     884
     885function TCustomAI.City_CurrentImprovementProject(cix: Integer): Integer;
     886begin
     887if MyCity[cix].Project and cpImp=0 then Result:=-1
    888888else
    889889  begin
    890   result:=MyCity[cix].Project and cpIndex;
    891   if result=imTrGoods then result:=-1
    892   end
    893 end;
    894 
    895 function TCustomAI.City_CurrentUnitProject(cix: integer): integer;
    896 begin
    897 if MyCity[cix].Project and cpImp<>0 then result:=-1
    898 else result:=MyCity[cix].Project and cpIndex;
    899 end;
    900 
    901 function TCustomAI.City_GetTileInfo(cix,TileLoc: integer; var TileInfo: TTileInfo): integer;
     890  Result:=MyCity[cix].Project and cpIndex;
     891  if Result=imTrGoods then Result:=-1
     892  end
     893end;
     894
     895function TCustomAI.City_CurrentUnitProject(cix: Integer): Integer;
     896begin
     897if MyCity[cix].Project and cpImp<>0 then Result:=-1
     898else Result:=MyCity[cix].Project and cpIndex;
     899end;
     900
     901function TCustomAI.City_GetTileInfo(cix,TileLoc: Integer; var TileInfo: TTileInfo): Integer;
    902902begin
    903903TileInfo.ExplCity:=cix;
    904 result:=Server(sGetHypoCityTileInfo,me,TileLoc,TileInfo)
    905 end;
    906 
    907 function TCustomAI.City_GetReport(cix: integer; var Report: TCityReport): integer;
     904Result:=Server(sGetHypoCityTileInfo,Me,TileLoc,TileInfo)
     905end;
     906
     907function TCustomAI.City_GetReport(cix: Integer; var Report: TCityReport): Integer;
    908908begin
    909909Report.HypoTiles:=-1;
    910910Report.HypoTax:=-1;
    911911Report.HypoLux:=-1;
    912 result:=Server(sGetCityReport,me,cix,Report)
    913 end;
    914 
    915 function TCustomAI.City_GetHypoReport(cix, HypoTiles, HypoTax, HypoLux: integer;
    916   var Report: TCityReport): integer;
     912Result:=Server(sGetCityReport,Me,cix,Report)
     913end;
     914
     915function TCustomAI.City_GetHypoReport(cix, HypoTiles, HypoTax, HypoLux: Integer;
     916  var Report: TCityReport): Integer;
    917917begin
    918918Report.HypoTiles:=HypoTiles;
    919919Report.HypoTax:=HypoTax;
    920920Report.HypoLux:=HypoLux;
    921 result:=Server(sGetCityReport,me,cix,Report)
    922 end;
    923 
    924 function TCustomAI.City_GetAreaInfo(cix: integer; var AreaInfo: TCityAreaInfo): integer;
    925 begin
    926 result:=Server(sGetCityAreaInfo,me,cix,AreaInfo)
    927 end;
    928 
    929 function TCustomAI.City_StartUnitProduction(cix,mix: integer): integer;
    930 begin
    931 result:=Server(sSetCityProject,me,cix,mix)
    932 end;
    933 
    934 function TCustomAI.City_StartEmigration(cix,mix: integer;
    935   AllowDisbandCity, AsConscripts: boolean): integer;
    936 var
    937 NewProject: integer;
     921Result:=Server(sGetCityReport,Me,cix,Report)
     922end;
     923
     924function TCustomAI.City_GetAreaInfo(cix: Integer; var AreaInfo: TCityAreaInfo): Integer;
     925begin
     926Result:=Server(sGetCityAreaInfo,Me,cix,AreaInfo)
     927end;
     928
     929function TCustomAI.City_StartUnitProduction(cix,mix: Integer): Integer;
     930begin
     931Result:=Server(sSetCityProject,Me,cix,mix)
     932end;
     933
     934function TCustomAI.City_StartEmigration(cix,mix: Integer;
     935  AllowDisbandCity, AsConscripts: Boolean): Integer;
     936var
     937NewProject: Integer;
    938938begin
    939939NewProject:=mix;
    940940if AllowDisbandCity then NewProject:=NewProject or cpDisbandCity;
    941941if AsConscripts then NewProject:=NewProject or cpConscripts;
    942 result:=Server(sSetCityProject,me,cix,NewProject)
    943 end;
    944 
    945 function TCustomAI.City_StartImprovement(cix,iix: integer): integer;
    946 var
    947 NewProject: integer;
     942Result:=Server(sSetCityProject,Me,cix,NewProject)
     943end;
     944
     945function TCustomAI.City_StartImprovement(cix,iix: Integer): Integer;
     946var
     947NewProject: Integer;
    948948begin
    949949NewProject:=iix+cpImp;
    950 result:=Server(sSetCityProject,me,cix,NewProject)
    951 end;
    952 
    953 function TCustomAI.City_Improvable(cix,iix: integer): boolean;
    954 var
    955 NewProject: integer;
     950Result:=Server(sSetCityProject,Me,cix,NewProject)
     951end;
     952
     953function TCustomAI.City_Improvable(cix,iix: Integer): Boolean;
     954var
     955NewProject: Integer;
    956956begin
    957957NewProject:=iix+cpImp;
    958 result:= Server(sSetCityProject-sExecute,me,cix,NewProject)>=rExecuted;
    959 end;
    960 
    961 function TCustomAI.City_StopProduction(cix: integer): integer;
    962 var
    963 NewProject: integer;
     958Result:= Server(sSetCityProject-sExecute,Me,cix,NewProject)>=rExecuted;
     959end;
     960
     961function TCustomAI.City_StopProduction(cix: Integer): Integer;
     962var
     963NewProject: Integer;
    964964begin
    965965NewProject:=imTrGoods+cpImp;
    966 result:=Server(sSetCityProject,me,cix,NewProject)
    967 end;
    968 
    969 function TCustomAI.City_BuyProject(cix: integer): integer;
    970 begin
    971 result:=Server(sBuyCityProject,me,cix,nodata^)
    972 end;
    973 
    974 function TCustomAI.City_SellImprovement(cix,iix: integer): integer;
    975 begin
    976 result:=Server(sSellCityImprovement,me,cix,iix)
    977 end;
    978 
    979 function TCustomAI.City_RebuildImprovement(cix,iix: integer): integer;
    980 begin
    981 result:=Server(sRebuildCityImprovement,me,cix,iix)
    982 end;
    983 
    984 function TCustomAI.City_SetTiles(cix,NewTiles: integer): integer;
    985 begin
    986 result:=Server(sSetCityTiles,me,cix,NewTiles)
     966Result:=Server(sSetCityProject,Me,cix,NewProject)
     967end;
     968
     969function TCustomAI.City_BuyProject(cix: Integer): Integer;
     970begin
     971Result:=Server(sBuyCityProject,Me,cix,nodata^)
     972end;
     973
     974function TCustomAI.City_SellImprovement(cix,iix: Integer): Integer;
     975begin
     976Result:=Server(sSellCityImprovement,Me,cix,iix)
     977end;
     978
     979function TCustomAI.City_RebuildImprovement(cix,iix: Integer): Integer;
     980begin
     981Result:=Server(sRebuildCityImprovement,Me,cix,iix)
     982end;
     983
     984function TCustomAI.City_SetTiles(cix,NewTiles: Integer): Integer;
     985begin
     986Result:=Server(sSetCityTiles,Me,cix,NewTiles)
    987987end;
    988988
    989989
    990990// negotiation
    991 function TCustomAI.Nego_CheckMyAction: integer;
    992 begin
    993 assert(Opponent>=0); // only allowed in negotiation mode
    994 assert((MyAction=scDipNotice) or (MyAction=scDipAccept)
     991function TCustomAI.Nego_CheckMyAction: Integer;
     992begin
     993Assert(Opponent>=0); // only allowed in negotiation mode
     994Assert((MyAction=scDipNotice) or (MyAction=scDipAccept)
    995995  or (MyAction=scDipCancelTreaty) or (MyAction=scDipOffer)
    996996  or (MyAction=scDipBreak));
    997 if MyAction=scDipOffer then result:=Server(MyAction-sExecute, me, 0, MyOffer)
    998 else result:=Server(MyAction-sExecute, me, 0, nodata^);
     997if MyAction=scDipOffer then Result:=Server(MyAction-sExecute, Me, 0, MyOffer)
     998else Result:=Server(MyAction-sExecute, Me, 0, nodata^);
    999999end;
    10001000
    10011001
    10021002initialization
    1003 nodata:=pointer(0);
     1003nodata:=Pointer(0);
    10041004RWDataSize:=0;
    10051005
Note: See TracChangeset for help on using the changeset viewer.