Changeset 583 for trunk


Ignore:
Timestamp:
May 23, 2024, 10:14:11 PM (7 months ago)
Author:
chronos
Message:
  • Modified: Code cleanup.
Location:
trunk
Files:
1 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/AI Template/AIProject.lpi

    r582 r583  
    9898        <IsPartOfProject Value="True"/>
    9999      </Unit>
     100      <Unit>
     101        <Filename Value="Names.pas"/>
     102        <IsPartOfProject Value="True"/>
     103      </Unit>
    100104    </Units>
    101105  </ProjectOptions>
  • trunk/AI Template/CustomAI.pas

    r582 r583  
    55
    66uses
    7   {$IFDEF DEBUG}SysUtils,{$ENDIF} // necessary for debug exceptions
     7{$IFDEF DEBUG}SysUtils,{$ENDIF} // necessary for debug exceptions
    88  Protocol;
    99
     
    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: integer = 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
     
    136136  // Unit_Move: move was not interrupted, location reached
    137137  rMoreTurns = $00020000;
    138   // Unit_Move: move was not interrupted, location not reached yet
     138// Unit_Move: move was not interrupted, location not reached yet
    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);
     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;
    155156
    156157
     
    158159
    159160const
    160   ab_v8: array[-4..4] of integer = (5, 6, 7, 4, -1, 0, 3, 2, 1);
    161   v8_a: array[0..7] of integer = (1, 1, 0, -1, -1, -1, 0, 1);
    162   v8_b: array[0..7] of integer = (0, 1, 1, 1, 0, -1, -1, -1);
    163 
    164 
    165 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);
    166167{relative location from Loc0}
    167168var
    168   y0: integer;
    169 begin
    170   assert((Loc0 >= 0) and (Loc0 < MapSize) and (a - b + G.lx >= 0));
    171   y0 := cardinal(Loc0) * decompose24 shr 24;
    172   Loc := (Loc0 + (a - b + y0 and 1 + G.lx + G.lx) shr 1) mod G.lx + G.lx * (y0 + a + b);
    173   if Loc >= MapSize then Loc := -$1000;
    174 end;
    175 
    176 
    177 procedure Loc_to_ab(Loc0,Loc: integer; var a,b: integer);
    178 {$IFDEF FPC} // freepascal
    179 var
    180   dx, dy: integer;
    181 begin
    182   dx := ((Loc mod G.lx * 2 + Loc div G.lx and 1)
    183     -(Loc0 mod G.lx *2 +Loc0 div G.lx and 1) + 3 * G.lx) mod (2 * G.lx) -G.lx;
     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);
     174  if Loc >= MapSize then
     175    Loc := -$1000;
     176end;
     177
     178procedure Loc_to_ab(Loc0, Loc: Integer; var A, B: Integer);
     179{$IFDEF FPC}// freepascal
     180var
     181  dx, dy: Integer;
     182begin
     183  dx := ((Loc mod G.lx * 2 + Loc div G.lx and 1) - (Loc0 mod G.lx * 2 + Loc0 div
     184    G.lx and 1) + 3 * G.lx) mod (2 * G.lx) - G.lx;
    184185  dy := Loc div G.lx - Loc0 div G.lx;
    185   a := (dx + dy) div 2;
    186   b := (dy - dx) div 2;
    187 end;
    188 {$ELSE} // delphi
     186  A := (dx + dy) div 2;
     187  B := (dy - dx) div 2;
     188end;
     189
     190{$ELSE}// delphi
    189191register;
    190192asm
    191   push ebx
    192 
    193   // calculate
    194   push ecx
    195   div byte ptr [G]
    196   xor ebx,ebx
    197   mov bl,ah  // ebx:=Loc0 mod G.lx
    198   mov ecx,eax
    199   and ecx,$000000FF // ecx:=Loc0 div G.lx
    200   mov eax,edx
    201   div byte ptr [G]
    202   xor edx,edx
    203   mov dl,ah // edx:=Loc mod G.lx
    204   and eax,$000000FF // eax:=Loc div G.lx
    205   sub edx,ebx // edx:=Loc mod G.lx-Loc0 mod G.lx
    206   mov ebx,eax
    207   sub ebx,ecx // ebx:=dy
    208   and eax,1
    209   and ecx,1
    210   add edx,edx
    211   add eax,edx
    212   sub eax,ecx // eax:=dx, not normalized
    213   pop ecx
    214 
    215   // normalize
    216   mov edx,dword ptr [G]
    217   cmp eax,edx
    218   jl @a
    219     sub eax,edx
    220     sub eax,edx
    221     jmp @ok
    222   @a:
    223   neg edx
    224   cmp eax,edx
    225   jnl @ok
    226     sub eax,edx
    227     sub eax,edx
    228 
    229   // return results
    230   @ok:
    231   mov edx,ebx
    232   sub edx,eax
    233   add eax,ebx
    234   sar edx,1 // edx:=b
    235   mov ebx,[b]
    236   mov [ebx],edx
    237   sar eax,1 // eax:=a
    238   mov [a],eax
    239 
    240   pop ebx
     193push ebx
     194
     195// calculate
     196push ecx
     197div Byte ptr [G]
     198xor ebx,ebx
     199mov bl,ah  // ebx:=Loc0 mod G.lx
     200mov ecx,eax
     201and ecx,$000000FF // ecx:=Loc0 div G.lx
     202mov eax,edx
     203div Byte ptr [G]
     204xor edx,edx
     205mov dl,ah // edx:=Loc mod G.lx
     206and eax,$000000FF // eax:=Loc div G.lx
     207sub edx,ebx // edx:=Loc mod G.lx-Loc0 mod G.lx
     208mov ebx,eax
     209sub ebx,ecx // ebx:=dy
     210and eax,1
     211and ecx,1
     212add edx,edx
     213add eax,edx
     214sub eax,ecx // eax:=dx, not normalized
     215pop ecx
     216
     217// normalize
     218mov edx,dword ptr [G]
     219cmp eax,edx
     220jl @A
     221  sub eax,edx
     222  sub eax,edx
     223  jmp @ok
     224@A:
     225neg edx
     226cmp eax,edx
     227jnl @ok
     228  sub eax,edx
     229  sub eax,edx
     230
     231// return results
     232@ok:
     233mov edx,ebx
     234sub edx,eax
     235add eax,ebx
     236sar edx,1 // edx:=b
     237mov ebx,[B]
     238mov [ebx],edx
     239sar eax,1 // eax:=a
     240mov [A],eax
     241
     242pop ebx
    241243end;
    242244{$ENDIF}
    243245
    244 procedure ab_to_V8(a, b: integer; var V8: integer);
    245 begin
    246   assert((abs(a) <= 1) and (abs(b) <= 1) and ((a <> 0) or (b <> 0)));
    247   V8 := ab_v8[2 * b + b + a];
    248 end;
    249 
    250 procedure V8_to_ab(V8: integer; var a, b: integer);
    251 begin
    252   a := v8_a[V8];
    253   b := V8_b[V8];
    254 end;
    255 
    256 procedure ab_to_V21(a, b: integer; var V21: integer);
    257 begin
    258   V21 := (a + b + 3) shl 2 + (a - b + 3) shr 1;
    259 end;
    260 
    261 procedure V21_to_ab(V21: integer; var a, b: integer);
    262 var
    263   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;
    264266begin
    265267  dy := V21 shr 2 - 3;
    266268  dx := V21 and 3 shl 1 - 3 + (dy + 3) and 1;
    267   a := (dx + dy) div 2;
    268   b := (dy - dx) div 2;
    269 end;
    270 
    271 procedure V8_to_Loc(Loc0: integer; var VicinityLoc: TVicinity8Loc);
    272 var
    273   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;
    274276begin
    275277  lx := G.lx;
    276   y0 := cardinal(Loc0) * decompose24 shr 24;
     278  y0 := Cardinal(Loc0) * decompose24 shr 24;
    277279  x0 := Loc0 - y0 * lx; // Loc0 mod lx;
    278280  VicinityLoc[1] := Loc0 + lx * 2;
     
    321323end;
    322324
    323 procedure V21_to_Loc(Loc0: integer; var VicinityLoc: TVicinity21Loc);
    324 var
    325   dx, dy, bit, y0, xComp, yComp, xComp0, xCompSwitch: integer;
    326   dst: ^integer;
    327 begin
    328   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;
    329331  xComp0 := Loc0 - y0 * G.lx - 1; // Loc0 mod G.lx -1
    330332  xCompSwitch := xComp0 - 1 + y0 and 1;
    331   if xComp0 < 0 then Inc(xComp0, G.lx);
    332   if xCompSwitch < 0 then Inc(xCompSwitch, G.lx);
     333  if xComp0 < 0 then
     334    Inc(xComp0, G.lx);
     335  if xCompSwitch < 0 then
     336    Inc(xCompSwitch, G.lx);
    333337  xCompSwitch := xCompSwitch xor xComp0;
    334338  yComp := G.lx * (y0 - 3);
     
    342346      for dx := 0 to 3 do
    343347      begin
    344         if bit and $67F7F76 <> 0 then dst^ := xComp + yComp
     348        if bit and $67F7F76 <> 0 then
     349          dst^ := xComp + yComp
    345350        else
    346351          dst^ := -1;
    347352        Inc(xComp);
    348         if xComp >= G.lx then Dec(xComp, G.lx);
     353        if xComp >= G.lx then
     354          Dec(xComp, G.lx);
    349355        Inc(dst);
    350356        bit := bit shl 1;
     
    362368end;
    363369
     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);
     377  Result := dx + dy + Abs(dx - dy) shr 1;
     378end;
    364379
    365380procedure Init(NewGameData: TNewGameData);
    366381{$IFDEF DEBUG}var
    367   Loc: integer;
    368   {$ENDIF}
     382  Loc: Integer;
     383{$ENDIF}
    369384begin
    370385  G := NewGameData;
    371386  MapSize := G.lx * G.ly;
    372387  decompose24 := (1 shl 24 - 1) div G.lx + 1;
    373   {$IFDEF DEBUG}
    374   for Loc := 0 to MapSize - 1 do assert(cardinal(Loc) * decompose24 shr
    375       24 = cardinal(Loc div G.lx));
    376   {$ENDIF}
    377 end;
    378 
    379 
    380 constructor TCustomAI.Create(Nation: integer);
     388{$IFDEF DEBUG}
     389  for Loc := 0 to MapSize - 1 do
     390    Assert(Cardinal(Loc) * decompose24 shr 24 = Cardinal(Loc div G.lx));
     391{$ENDIF}
     392end;
     393
     394constructor TCustomAI.Create(Nation: Integer);
    381395begin
    382396  inherited Create;
    383   me := Nation;
    384   RO := pointer(G.RO[Nation]);
    385   Map := pointer(RO.Map);
    386   MyUnit := pointer(RO.Un);
    387   MyCity := pointer(RO.City);
    388   MyModel := pointer(RO.Model);
     397  Me := Nation;
     398  RO := Pointer(G.RO[Nation]);
     399  Map := Pointer(RO.Map);
     400  MyUnit := Pointer(RO.Un);
     401  MyCity := Pointer(RO.City);
     402  MyModel := Pointer(RO.Model);
    389403  Opponent := -1;
    390404end;
     
    392406destructor TCustomAI.Destroy;
    393407begin
    394   Server(sSetDebugMap, me, 0, nodata^);
    395 end;
    396 
    397 
    398 procedure TCustomAI.Process(Command: integer; var Data);
    399 var
    400   Nation, NewResearch, NewGov, Count, ad, cix, iix: integer;
     408  Server(sSetDebugMap, Me, 0, nodata^);
     409end;
     410
     411procedure TCustomAI.Process(Command: Integer; var Data);
     412var
     413  Nation, NewResearch, NewGov, Count, ad, cix, iix: Integer;
    401414  NegoTime: TNegoTime;
    402415begin
     
    404417    cTurn, cContinue:
    405418    begin
    406       if RO.Alive and (1 shl me) = 0 then
     419      if RO.Alive and (1 shl Me) = 0 then
    407420      begin // I'm dead, huhu
    408         Server(sTurn, me, 0, nodata^);
    409         exit;
     421        Server(sTurn, Me, 0, nodata^);
     422        Exit;
    410423      end;
    411424      if Command = cTurn then
    412425      begin
    413         fillchar(cixStateImp, sizeof(cixStateImp), $FF);
    414         for cix := 0 to RO.nCity - 1 do if MyCity[cix].Loc >= 0 then
     426        FillChar(cixStateImp, SizeOf(cixStateImp), $FF);
     427        for cix := 0 to RO.nCity - 1 do
     428          if MyCity[cix].Loc >= 0 then
    415429            for iix := imPalace to imSpacePort do
    416430              if MyCity[cix].Built[iix] > 0 then
     
    420434          NewGov := ChooseGovernment;
    421435          if NewGov > gAnarchy then
    422             Server(sSetGovernment, me, NewGov, nodata^);
     436            Server(sSetGovernment, Me, NewGov, nodata^);
    423437        end;
    424438        HaveTurned := False;
     
    429443        if OnNegoRejected_CancelTreaty then
    430444          if RO.Treaty[Opponent] >= trPeace then
    431             if Server(sCancelTreaty, me, 0, nodata^) < rExecuted then
    432               assert(False);
     445            if Server(sCancelTreaty, Me, 0, nodata^) < rExecuted then
     446              Assert(False);
    433447      end
    434448      else
     
    436450      Opponent := -1;
    437451      repeat
    438         if HaveTurned then NegoTime := EndOfTurn
     452        if HaveTurned then
     453          NegoTime := EndOfTurn
    439454        else
    440455          NegoTime := BeginOfTurn;
    441456        if RO.Government <> gAnarchy then
    442457          for Nation := 0 to nPl - 1 do
    443             if (Nation <> me) and (1 shl Nation and RO.Alive <> 0) and
     458            if (Nation <> Me) and (1 shl Nation and RO.Alive <> 0) and
    444459              (RO.Treaty[Nation] >= trNone) and not (Nation in Contacted) and not
    445460              (Nation in UnwantedNego) and
    446               (Server(scContact - sExecute + Nation shl 4, me, 0, nodata^) >= rExecuted) then
     461              (Server(scContact - sExecute + Nation shl 4, Me, 0, nodata^) >= rExecuted) then
    447462              if WantNegotiation(Nation, NegoTime) then
    448463              begin
    449                 if Server(scContact + Nation shl 4, me, 0, nodata^) >= rExecuted then
     464                if Server(scContact + Nation shl 4, Me, 0, nodata^) >= rExecuted then
    450465                begin
    451                   include(Contacted, Nation);
     466                  Include(Contacted, Nation);
    452467                  Opponent := Nation;
    453468                  MyAction := scContact;
    454                   exit;
     469                  Exit;
    455470                end;
    456471              end
    457472              else
    458                 include(UnwantedNego, Nation);
     473                Include(UnwantedNego, Nation);
    459474        if NegoTime = BeginOfTurn then
    460475        begin
     
    465480        end
    466481        else
    467           break;
     482          Break;
    468483      until False;
    469484      if RO.Happened and phTech <> 0 then
     
    473488        begin // choose random research
    474489          Count := 0;
    475           for ad := 0 to nAdv - 1 do if AdvanceResearchable(ad) then
     490          for ad := 0 to nAdv - 1 do
     491            if AdvanceResearchable(ad) then
    476492            begin
    477493              Inc(Count);
    478               if random(Count) = 0 then NewResearch := ad;
     494              if Random(Count) = 0 then
     495                NewResearch := ad;
    479496            end;
    480497        end;
    481         Server(sSetResearch, me, NewResearch, nodata^);
     498        Server(sSetResearch, Me, NewResearch, nodata^);
    482499      end;
    483       if Server(sTurn, me, 0, nodata^) < rExecuted then
    484         assert(False);
     500      if Server(sTurn, Me, 0, nodata^) < rExecuted then
     501        Assert(False);
    485502    end;
    486503    scContact:
    487       if WantNegotiation(integer(Data), EnemyCalled) then
     504      if WantNegotiation(Integer(Data), EnemyCalled) then
    488505      begin
    489         if Server(scDipStart, me, 0, nodata^) < rExecuted then
    490           assert(False);
    491         Opponent := integer(Data);
     506        if Server(scDipStart, Me, 0, nodata^) < rExecuted then
     507          Assert(False);
     508        Opponent := Integer(Data);
    492509        MyAction := scDipStart;
    493510      end
    494511      else
    495512      begin
    496         if Server(scReject, me, 0, nodata^) < rExecuted then
    497           assert(False);
     513        if Server(scReject, Me, 0, nodata^) < rExecuted then
     514          Assert(False);
    498515      end;
    499516    scDipStart, scDipNotice, scDipAccept, scDipCancelTreaty, scDipOffer, scDipBreak:
    500517    begin
    501518      OppoAction := Command;
    502       if Command = scDipOffer then OppoOffer := TOffer(Data);
     519      if Command = scDipOffer then
     520        OppoOffer := TOffer(Data);
    503521      if Command = scDipStart then
    504522        MyLastAction := scContact
     
    517535      end;
    518536      DoNegotiation;
    519       assert((MyAction = scDipNotice) or (MyAction = scDipAccept) or
     537      Assert((MyAction = scDipNotice) or (MyAction = scDipAccept) or
    520538        (MyAction = scDipCancelTreaty) or (MyAction = scDipOffer) or (MyAction = scDipBreak));
    521       if MyAction = scDipOffer then Server(MyAction, me, 0, MyOffer)
     539      if MyAction = scDipOffer then
     540        Server(MyAction, Me, 0, MyOffer)
    522541      else
    523         Server(MyAction, me, 0, nodata^);
     542        Server(MyAction, Me, 0, nodata^);
    524543    end;
    525544    cShowEndContact:
     
    546565
    547566procedure TCustomAI.OnBeforeEnemyAttack(UnitInfo: TUnitInfo;
    548   ToLoc, EndHealth, EndHealthDef: integer);
    549 begin
    550 end;
    551 
    552 procedure TCustomAI.OnBeforeEnemyCapture(UnitInfo: TUnitInfo; ToLoc: integer);
     567  ToLoc, EndHealth, EndHealthDef: Integer);
     568begin
     569end;
     570
     571procedure TCustomAI.OnBeforeEnemyCapture(UnitInfo: TUnitInfo; ToLoc: Integer);
    553572begin
    554573end;
     
    562581end;
    563582
    564 function TCustomAI.ChooseResearchAdvance: integer;
     583function TCustomAI.ChooseResearchAdvance: Integer;
    565584begin
    566585  Result := -1;
    567586end;
    568587
    569 function TCustomAI.ChooseStealAdvance: integer;
     588function TCustomAI.ChooseStealAdvance: Integer;
    570589begin
    571590  Result := -1;
    572591end;
    573592
    574 function TCustomAI.ChooseGovernment: integer;
     593function TCustomAI.ChooseGovernment: Integer;
    575594begin
    576595  Result := gDespotism;
    577596end;
    578597
    579 function TCustomAI.WantNegotiation(Nation: integer; NegoTime: TNegoTime): boolean;
     598function TCustomAI.WantNegotiation(Nation: Integer; NegoTime: TNegoTime): Boolean;
    580599begin
    581600  Result := False;
    582601end;
    583602
    584 function TCustomAI.OnNegoRejected_CancelTreaty: boolean;
     603function TCustomAI.OnNegoRejected_CancelTreaty: Boolean;
    585604begin
    586605  Result := False;
    587606end;
     607
    588608{$HINTS ON}
    589609
    590610procedure TCustomAI.StealAdvance;
    591611var
    592   Steal, ad, Count: integer;
     612  Steal, ad, Count: Integer;
    593613begin
    594614  Steal := ChooseStealAdvance;
     
    596616  begin // choose random advance
    597617    Count := 0;
    598     for ad := 0 to nAdv - 1 do if AdvanceStealable(ad) then
     618    for ad := 0 to nAdv - 1 do
     619      if AdvanceStealable(ad) then
    599620      begin
    600621        Inc(Count);
    601         if random(Count) = 0 then Steal := ad;
     622        if Random(Count) = 0 then
     623          Steal := ad;
    602624      end;
    603625  end;
    604   if Steal >= 0 then Server(sStealTech, me, Steal, nodata^);
     626  if Steal >= 0 then
     627    Server(sStealTech, Me, Steal, nodata^);
    605628  RO.Happened := RO.Happened and not phStealTech;
    606629end;
    607630
    608 function TCustomAI.IsResearched(Advance: integer): boolean;
    609 begin
    610   Result := RO.Tech[Advance] >= tsApplicable;
    611 end;
    612 
    613 function TCustomAI.ResearchCost: integer;
    614 begin
    615   Server(sGetTechCost, me, 0, Result);
    616 end;
    617 
    618 function TCustomAI.ChangeAttitude(Nation, Attitude: integer): integer;
    619 begin
    620   Result := Server(sSetAttitude + Nation shl 4, me, Attitude, nodata^);
    621 end;
    622 
    623 function TCustomAI.Revolution: integer;
    624 begin
    625   Result := Server(sRevolution, me, 0, nodata^);
    626 end;
    627 
    628 function TCustomAI.ChangeRates(Tax, Lux: integer): integer;
    629 begin
    630   Result := Server(sSetRates, me, Tax div 10 and $f + Lux div 10 and $f shl 4, nodata^);
    631 end;
    632 
    633 function TCustomAI.PrepareNewModel(Domain: integer): integer;
    634 begin
    635   Result := Server(sCreateDevModel, me, Domain, nodata^);
    636 end;
    637 
    638 function TCustomAI.SetNewModelFeature(F, Count: integer): integer;
    639 begin
    640   Result := Server(sSetDevModelCap + Count shl 4, me, F, nodata^);
    641 end;
    642 
    643 function TCustomAI.AdvanceResearchable(Advance: integer): boolean;
    644 begin
    645   Result := Server(sSetResearch - sExecute, me, Advance, nodata^) >= rExecuted;
    646 end;
    647 
    648 function TCustomAI.AdvanceStealable(Advance: integer): boolean;
    649 begin
    650   Result := Server(sStealTech - sExecute, me, Advance, nodata^) >= rExecuted;
    651 end;
    652 
    653 function TCustomAI.GetJobProgress(Loc: integer;
    654   var JobProgress: TJobProgressData): boolean;
    655 begin
    656   Result := Server(sGetJobProgress, me, Loc, JobProgress) >= rExecuted;
    657 end;
    658 
    659 function TCustomAI.DebugMessage(Level: integer; Text: string): boolean;
    660 begin
    661   Text := copy('P' + char(48 + me) + ' ' + Text, 1, 254);
    662   Server(sMessage, me, Level, PChar(Text)^);
     631function TCustomAI.IsResearched(Advance: Integer): Boolean;
     632begin
     633  Result := (Advance = preNone) or (Advance <> preNA) and (RO.Tech[Advance] >= tsApplicable);
     634end;
     635
     636function TCustomAI.ResearchCost: Integer;
     637begin
     638  Server(sGetTechCost, Me, 0, Result);
     639end;
     640
     641function TCustomAI.ChangeAttitude(Nation, Attitude: Integer): Integer;
     642begin
     643  Result := Server(sSetAttitude + Nation shl 4, Me, Attitude, nodata^);
     644end;
     645
     646function TCustomAI.Revolution: Integer;
     647begin
     648  Result := Server(sRevolution, Me, 0, nodata^);
     649end;
     650
     651function TCustomAI.ChangeRates(Tax, Lux: Integer): Integer;
     652begin
     653  Result := Server(sSetRates, Me, Tax div 10 and $F + Lux div 10 and $F shl 4, nodata^);
     654end;
     655
     656function TCustomAI.PrepareNewModel(Domain: Integer): Integer;
     657begin
     658  Result := Server(sCreateDevModel, Me, Domain, nodata^);
     659end;
     660
     661function TCustomAI.SetNewModelFeature(F, Count: Integer): Integer;
     662begin
     663  Result := Server(sSetDevModelCap + Count shl 4, Me, F, nodata^);
     664end;
     665
     666function TCustomAI.AdvanceResearchable(Advance: Integer): Boolean;
     667begin
     668  Result := Server(sSetResearch - sExecute, Me, Advance, nodata^) >= rExecuted;
     669end;
     670
     671function TCustomAI.AdvanceStealable(Advance: Integer): Boolean;
     672begin
     673  Result := Server(sStealTech - sExecute, Me, Advance, nodata^) >= rExecuted;
     674end;
     675
     676function TCustomAI.GetJobProgress(Loc: Integer;
     677  var JobProgress: TJobProgressData): Boolean;
     678begin
     679  Result := Server(sGetJobProgress, Me, Loc, JobProgress) >= rExecuted;
     680end;
     681
     682function TCustomAI.DebugMessage(Level: Integer; Text: string): Boolean;
     683begin
     684  Text := Copy('P' + Char(48 + Me) + ' ' + Text, 1, 254);
     685  Server(sMessage, Me, Level, PChar(Text)^);
    663686
    664687  Result := True;
     
    667690end;
    668691
    669 function TCustomAI.SetDebugMap(var DebugMap): boolean;
    670 begin
    671   Server(sSetDebugMap, me, 0, DebugMap);
     692function TCustomAI.SetDebugMap(var DebugMap): Boolean;
     693begin
     694  Server(sSetDebugMap, Me, 0, DebugMap);
    672695
    673696  Result := True;
     
    676699end;
    677700
    678 procedure TCustomAI.Unit_FindMyDefender(Loc: integer; var uix: integer);
    679 begin
    680   if Server(sGetDefender, me, Loc, uix) < rExecuted then uix := -1;
    681 end;
    682 
    683 procedure TCustomAI.Unit_FindEnemyDefender(Loc: integer; var euix: integer);
     701procedure TCustomAI.Unit_FindMyDefender(Loc: Integer; var uix: Integer);
     702begin
     703  if Server(sGetDefender, Me, Loc, uix) < rExecuted then
     704    uix := -1;
     705end;
     706
     707procedure TCustomAI.Unit_FindEnemyDefender(Loc: Integer; var euix: Integer);
    684708begin
    685709  euix := RO.nEnemyUn - 1;
     
    688712end;
    689713
    690 function TCustomAI.Unit_Move(uix, ToLoc: integer): integer;
    691 var
    692   Step: integer;
    693   DestinationReached: boolean;
     714function TCustomAI.Unit_Move(uix, ToLoc: Integer): Integer;
     715var
     716  Step: Integer;
     717  DestinationReached: Boolean;
    694718  Advice: TMoveAdviceData;
    695719begin
    696   assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0)); // is a unit
     720  Assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0)); // is a unit
    697721{Loc_to_ab(MyUnit[uix].Loc,ToLoc,a,b);
    698 assert((a<>0) or (b<>0));
    699 if (a>=-1) and (a<=1) and (b>=-1) and (b<=1) then
     722Assert((A<>0) or (B<>0));
     723if (A>=-1) and (A<=1) and (B>=-1) and (B<=1) then
    700724  begin // move to adjacent tile
    701   !!!problem: if move is invalid, return codes are not consistent with other branch (eNoWay)
     725  !!!problem: if Move is invalid, return codes are not consistent with other branch (eNoWay)
    702726  Advice.nStep:=1;
    703   Advice.dx[0]:=a-b;
    704   Advice.dy[0]:=a+b;
     727  Advice.dx[0]:=A-B;
     728  Advice.dy[0]:=A+B;
    705729  Advice.MoreTurns:=0;
    706730  Advice.MaxHostile_MovementLeft:=MyUnit[uix].Movement;
    707   result:=eOK;
     731  Result:=eOK;
    708732  end
    709733else}
     
    712736    Advice.MoreTurns := 9999;
    713737    Advice.MaxHostile_MovementLeft := 100;
    714     Result := Server(sGetMoveAdvice, me, uix, Advice);
     738    Result := Server(sGetMoveAdvice, Me, uix, Advice);
    715739  end;
    716740  if Result = eOk then
     
    728752        begin
    729753          DestinationReached := True;
    730           break;
     754          Break;
    731755        end // stop next to destination
    732756        else if Step = Advice.nStep then
     
    734758
    735759      if (Step = Advice.nStep) or (Result <> eOK) and (Result <> eLoaded) then
    736         break;
     760        Break;
    737761
    738762      Result := Server(sMoveUnit + (Advice.dx[Step] and 7) shl 4 +
    739         (Advice.dy[Step] and 7) shl 7, me, uix, nodata^);
     763        (Advice.dy[Step] and 7) shl 7, Me, uix, nodata^);
    740764      Inc(Step);
    741       if RO.Happened and phStealTech <> 0 then StealAdvance;
     765      if RO.Happened and phStealTech <> 0 then
     766        StealAdvance;
    742767    until False;
    743768    if DestinationReached then
     
    751776end;
    752777
    753 function TCustomAI.Unit_Step(uix, ToLoc: integer): integer;
    754 var
    755   a, b: integer;
    756 begin
    757   Loc_to_ab(MyUnit[uix].Loc, ToLoc, a, b);
    758   assert(((a <> 0) or (b <> 0)) and (a >= -1) and (a <= 1) and (b >= -1) and (b <= 1));
    759   Result := Server(sMoveUnit + ((a - b) and 7) shl 4 + ((a + b) and 7) shl 7, me, uix, nodata^);
    760   if RO.Happened and phStealTech <> 0 then StealAdvance;
    761 end;
    762 
    763 function TCustomAI.Unit_Attack(uix, ToLoc: integer): integer;
    764 var
    765   a, b: integer;
    766 begin
    767   assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0) // is a unit
     778function TCustomAI.Unit_Step(uix, ToLoc: Integer): Integer;
     779var
     780  A, B: Integer;
     781begin
     782  Loc_to_ab(MyUnit[uix].Loc, ToLoc, A, B);
     783  Assert(((A <> 0) or (B <> 0)) and (A >= -1) and (A <= 1) and (B >= -1) and (B <= 1));
     784  Result := Server(sMoveUnit + ((A - B) and 7) shl 4 + ((A + B) and 7) shl 7, Me, uix, nodata^);
     785  if RO.Happened and phStealTech <> 0 then
     786    StealAdvance;
     787end;
     788
     789function TCustomAI.Unit_Attack(uix, ToLoc: Integer): Integer;
     790var
     791  A, B: Integer;
     792begin
     793  Assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0) // is a unit
    768794    and ((Map[ToLoc] and (fUnit or fOwned) = fUnit) // is an attack
    769795    or (Map[ToLoc] and (fCity or fOwned) = fCity) and
    770796    (MyModel[MyUnit[uix].mix].Domain <> dGround))); // is a bombardment
    771   Loc_to_ab(MyUnit[uix].Loc, ToLoc, a, b);
    772   assert(((a <> 0) or (b <> 0)) and (a >= -1) and (a <= 1) and (b >= -1) and (b <= 1));
     797  Loc_to_ab(MyUnit[uix].Loc, ToLoc, A, B);
     798  Assert(((A <> 0) or (B <> 0)) and (A >= -1) and (A <= 1) and (B >= -1) and (B <= 1));
    773799  // attack to adjacent tile
    774   Result := Server(sMoveUnit + (a - b) and 7 shl 4 + (a + b) and 7 shl 7, me, uix, nodata^);
    775 end;
    776 
    777 function TCustomAI.Unit_DoMission(uix, MissionType, ToLoc: integer): integer;
    778 var
    779   a, b: integer;
    780 begin
    781   Result := Server(sSetSpyMission + MissionType shl 4, me, 0, nodata^);
     800  Result := Server(sMoveUnit + (A - B) and 7 shl 4 + (A + B) and 7 shl 7, Me, uix, nodata^);
     801end;
     802
     803function TCustomAI.Unit_DoMission(uix, MissionType, ToLoc: Integer): Integer;
     804var
     805  A, B: Integer;
     806begin
     807  Result := Server(sSetSpyMission + MissionType shl 4, Me, 0, nodata^);
    782808  if Result >= rExecuted then
    783809  begin
    784     assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0) // is a unit
     810    Assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0) // is a unit
    785811      and (MyModel[MyUnit[uix].mix].Kind = mkDiplomat)); // is a commando
    786     Loc_to_ab(MyUnit[uix].Loc, ToLoc, a, b);
    787     assert(((a <> 0) or (b <> 0)) and (a >= -1) and (a <= 1) and (b >= -1) and (b <= 1));
     812    Loc_to_ab(MyUnit[uix].Loc, ToLoc, A, B);
     813    Assert(((A <> 0) or (B <> 0)) and (A >= -1) and (A <= 1) and (B >= -1) and (B <= 1));
    788814    // city must be adjacent
    789     Result := Server(sMoveUnit - sExecute + (a - b) and 7 shl 4 + (a + b) and 7 shl 7, me, uix, nodata^);
     815    Result := Server(sMoveUnit - sExecute + (A - B) and 7 shl 4 + (A + B) and 7 shl 7, Me, uix, nodata^);
    790816    if Result = eMissionDone then
    791       Result := Server(sMoveUnit + (a - b) and 7 shl 4 + (a + b) and 7 shl 7, me, uix, nodata^)
     817      Result := Server(sMoveUnit + (A - B) and 7 shl 4 + (A + B) and 7 shl 7, Me, uix, nodata^)
    792818    else if (Result <> eNoTime_Move) and (Result <> eTreaty) and (Result <> eNoTurn) then
    793819      Result := eInvalid; // not a special commando mission!
     
    795821end;
    796822
    797 function TCustomAI.Unit_MoveForecast(uix, ToLoc: integer;
    798   var RemainingMovement: integer): boolean;
     823function TCustomAI.Unit_MoveForecast(uix, ToLoc: Integer;
     824  var RemainingMovement: Integer): Boolean;
    799825var
    800826  Advice: TMoveAdviceData;
    801827begin
    802   assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0)); // is a unit
     828  Assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0)); // is a unit
    803829  Advice.ToLoc := ToLoc;
    804830  Advice.MoreTurns := 0;
    805831  Advice.MaxHostile_MovementLeft := 100;
    806   if Server(sGetMoveAdvice, me, uix, Advice) = eOk then
     832  if Server(sGetMoveAdvice, Me, uix, Advice) = eOk then
    807833  begin
    808834    RemainingMovement := Advice.MaxHostile_MovementLeft;
     
    816842end;
    817843
    818 function TCustomAI.Unit_AttackForecast(uix, ToLoc, AttackMovement: integer;
    819   var RemainingHealth: integer): boolean;
     844// negative RemainingHealth is remaining helth of defender if lost
     845function TCustomAI.Unit_AttackForecast(uix, ToLoc, AttackMovement: Integer;
     846  var RemainingHealth: Integer): Boolean;
    820847var
    821848  BattleForecast: TBattleForecast;
    822849begin
    823   assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0) // is a unit
     850  Assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0) // is a unit
    824851    and (Map[ToLoc] and (fUnit or fOwned) = fUnit)); // is an attack
    825852  RemainingHealth := -$100;
    826853  Result := False;
    827   if AttackMovement >= 0 then with MyUnit[uix] do
     854  if AttackMovement >= 0 then
     855    with MyUnit[uix] do
    828856    begin
    829       BattleForecast.pAtt := me;
     857      BattleForecast.pAtt := Me;
    830858      BattleForecast.mixAtt := mix;
    831859      BattleForecast.HealthAtt := Health;
     
    833861      BattleForecast.FlagsAtt := Flags;
    834862      BattleForecast.Movement := AttackMovement;
    835       if Server(sGetBattleForecast, me, ToLoc, BattleForecast) >= rExecuted then
     863      if Server(sGetBattleForecast, Me, ToLoc, BattleForecast) >= rExecuted then
    836864      begin
    837865        if BattleForecast.EndHealthAtt > 0 then
     
    844872end;
    845873
    846 function TCustomAI.Unit_DefenseForecast(euix, ToLoc: integer;
    847   var RemainingHealth: integer): boolean;
     874function TCustomAI.Unit_DefenseForecast(euix, ToLoc: Integer;
     875  var RemainingHealth: Integer): Boolean;
    848876var
    849877  BattleForecast: TBattleForecast;
    850878begin
    851   assert((euix >= 0) and (euix < RO.nEnemyUn) and (RO.EnemyUn[euix].Loc >= 0) // is an enemy unit
     879  Assert((euix >= 0) and (euix < RO.nEnemyUn) and (RO.EnemyUn[euix].Loc >= 0) // is an enemy unit
    852880    and (Map[ToLoc] and (fUnit or fOwned) = (fUnit or fOwned))); // is an attack
    853881  RemainingHealth := $100;
     
    861889    BattleForecast.FlagsAtt := Flags;
    862890    BattleForecast.Movement := 100;
    863     if Server(sGetBattleForecast, me, ToLoc, BattleForecast) >= rExecuted then
     891    if Server(sGetBattleForecast, Me, ToLoc, BattleForecast) >= rExecuted then
    864892    begin
    865893      if BattleForecast.EndHealthDef > 0 then
     
    872900end;
    873901
    874 function TCustomAI.Unit_Disband(uix: integer): integer;
    875 begin
    876   Result := Server(sRemoveUnit, me, uix, nodata^);
    877 end;
    878 
    879 function TCustomAI.Unit_StartJob(uix, NewJob: integer): integer;
    880 begin
    881   Result := Server(sStartJob + NewJob shl 4, me, uix, nodata^);
    882 end;
    883 
    884 function TCustomAI.Unit_SetHomeHere(uix: integer): integer;
    885 begin
    886   Result := Server(sSetUnitHome, me, uix, nodata^);
    887 end;
    888 
    889 function TCustomAI.Unit_Load(uix: integer): integer;
    890 begin
    891   Result := Server(sLoadUnit, me, uix, nodata^);
    892 end;
    893 
    894 function TCustomAI.Unit_Unload(uix: integer): integer;
    895 begin
    896   Result := Server(sUnloadUnit, me, uix, nodata^);
    897 end;
    898 
    899 function TCustomAI.Unit_AddToCity(uix: integer): integer;
    900 begin
    901   Result := Server(sAddToCity, me, uix, nodata^);
    902 end;
    903 
    904 function TCustomAI.Unit_SelectTransport(uix: integer): integer;
    905 begin
    906   Result := Server(sSelectTransport, me, uix, nodata^);
    907 end;
    908 
    909 
    910 procedure TCustomAI.City_FindMyCity(Loc: integer; var cix: integer);
     902function TCustomAI.Unit_Disband(uix: Integer): Integer;
     903begin
     904  Result := Server(sRemoveUnit, Me, uix, nodata^);
     905end;
     906
     907function TCustomAI.Unit_StartJob(uix, NewJob: Integer): Integer;
     908begin
     909  Result := Server(sStartJob + NewJob shl 4, Me, uix, nodata^);
     910end;
     911
     912function TCustomAI.Unit_SetHomeHere(uix: Integer): Integer;
     913begin
     914  Result := Server(sSetUnitHome, Me, uix, nodata^);
     915end;
     916
     917function TCustomAI.Unit_Load(uix: Integer): Integer;
     918begin
     919  Result := Server(sLoadUnit, Me, uix, nodata^);
     920end;
     921
     922function TCustomAI.Unit_Unload(uix: Integer): Integer;
     923begin
     924  Result := Server(sUnloadUnit, Me, uix, nodata^);
     925end;
     926
     927function TCustomAI.Unit_AddToCity(uix: Integer): Integer;
     928begin
     929  Result := Server(sAddToCity, Me, uix, nodata^);
     930end;
     931
     932function TCustomAI.Unit_SelectTransport(uix: Integer): Integer;
     933begin
     934  Result := Server(sSelectTransport, Me, uix, nodata^);
     935end;
     936
     937
     938procedure TCustomAI.City_FindMyCity(Loc: Integer; var cix: Integer);
    911939begin
    912940  if Map[Loc] and (fCity or fOwned) <> fCity or fOwned then
     
    920948end;
    921949
    922 procedure TCustomAI.City_FindEnemyCity(Loc: integer; var ecix: integer);
     950procedure TCustomAI.City_FindEnemyCity(Loc: Integer; var ecix: Integer);
    923951begin
    924952  if Map[Loc] and (fCity or fOwned) <> fCity then
     
    932960end;
    933961
    934 function TCustomAI.City_HasProject(cix: integer): boolean;
     962function TCustomAI.City_HasProject(cix: Integer): Boolean;
    935963begin
    936964  Result := MyCity[cix].Project and (cpImp + cpIndex) <> cpImp + imTrGoods;
    937965end;
    938966
    939 function TCustomAI.City_CurrentImprovementProject(cix: integer): integer;
    940 begin
    941   if MyCity[cix].Project and cpImp = 0 then Result := -1
     967function TCustomAI.City_CurrentImprovementProject(cix: Integer): Integer;
     968begin
     969  if MyCity[cix].Project and cpImp = 0 then
     970    Result := -1
    942971  else
    943972  begin
    944973    Result := MyCity[cix].Project and cpIndex;
    945     if Result = imTrGoods then Result := -1;
    946   end;
    947 end;
    948 
    949 function TCustomAI.City_CurrentUnitProject(cix: integer): integer;
    950 begin
    951   if MyCity[cix].Project and cpImp <> 0 then Result := -1
     974    if Result = imTrGoods then
     975      Result := -1;
     976  end;
     977end;
     978
     979function TCustomAI.City_CurrentUnitProject(cix: Integer): Integer;
     980begin
     981  if MyCity[cix].Project and cpImp <> 0 then
     982    Result := -1
    952983  else
    953984    Result := MyCity[cix].Project and cpIndex;
    954985end;
    955986
    956 function TCustomAI.City_GetTileInfo(cix, TileLoc: integer;
    957   var TileInfo: TTileInfo): integer;
     987function TCustomAI.City_GetTileInfo(cix, TileLoc: Integer;
     988  var TileInfo: TTileInfo): Integer;
    958989begin
    959990  TileInfo.ExplCity := cix;
    960   Result := Server(sGetHypoCityTileInfo, me, TileLoc, TileInfo);
    961 end;
    962 
    963 function TCustomAI.City_GetReport(cix: integer; var Report: TCityReport): integer;
     991  Result := Server(sGetHypoCityTileInfo, Me, TileLoc, TileInfo);
     992end;
     993
     994function TCustomAI.City_GetReport(cix: Integer; var Report: TCityReport): Integer;
    964995begin
    965996  Report.HypoTiles := -1;
    966997  Report.HypoTax := -1;
    967998  Report.HypoLux := -1;
    968   Result := Server(sGetCityReport, me, cix, Report);
    969 end;
    970 
    971 function TCustomAI.City_GetHypoReport(cix, HypoTiles, HypoTax, HypoLux: integer;
    972   var Report: TCityReport): integer;
     999  Result := Server(sGetCityReport, Me, cix, Report);
     1000end;
     1001
     1002function TCustomAI.City_GetHypoReport(cix, HypoTiles, HypoTax, HypoLux: Integer;
     1003  var Report: TCityReport): Integer;
    9731004begin
    9741005  Report.HypoTiles := HypoTiles;
    9751006  Report.HypoTax := HypoTax;
    9761007  Report.HypoLux := HypoLux;
    977   Result := Server(sGetCityReport, me, cix, Report);
    978 end;
    979 
    980 function TCustomAI.City_GetReportNew(cix: integer; var Report: TCityReportNew): integer;
     1008  Result := Server(sGetCityReport, Me, cix, Report);
     1009end;
     1010
     1011function TCustomAI.City_GetReportNew(cix: Integer; var Report: TCityReportNew): Integer;
    9811012begin
    9821013  Report.HypoTiles := -1;
    9831014  Report.HypoTaxRate := -1;
    9841015  Report.HypoLuxuryRate := -1;
    985   Result := Server(sGetCityReportNew, me, cix, Report);
     1016  Result := Server(sGetCityReportNew, Me, cix, Report);
    9861017end;
    9871018
    9881019function TCustomAI.City_GetHypoReportNew(cix, HypoTiles, HypoTaxRate,
    989   HypoLuxuryRate: integer; var Report: TCityReportNew): integer;
     1020  HypoLuxuryRate: Integer; var Report: TCityReportNew): Integer;
    9901021begin
    9911022  Report.HypoTiles := HypoTiles;
    9921023  Report.HypoTaxRate := HypoTaxRate;
    9931024  Report.HypoLuxuryRate := HypoLuxuryRate;
    994   Result := Server(sGetCityReportNew, me, cix, Report);
    995 end;
    996 
    997 function TCustomAI.City_GetAreaInfo(cix: integer; var AreaInfo: TCityAreaInfo): integer;
    998 begin
    999   Result := Server(sGetCityAreaInfo, me, cix, AreaInfo);
    1000 end;
    1001 
    1002 function TCustomAI.City_StartUnitProduction(cix, mix: integer): integer;
    1003 begin
    1004   Result := Server(sSetCityProject, me, cix, mix);
    1005 end;
    1006 
    1007 function TCustomAI.City_StartEmigration(cix, mix: integer;
    1008   AllowDisbandCity, AsConscripts: boolean): integer;
    1009 var
    1010   NewProject: integer;
     1025  Result := Server(sGetCityReportNew, Me, cix, Report);
     1026end;
     1027
     1028function TCustomAI.City_GetAreaInfo(cix: Integer; var AreaInfo: TCityAreaInfo): Integer;
     1029begin
     1030  Result := Server(sGetCityAreaInfo, Me, cix, AreaInfo);
     1031end;
     1032
     1033function TCustomAI.City_StartUnitProduction(cix, mix: Integer): Integer;
     1034begin
     1035  if (MyCity[cix].Project and (cpImp + cpIndex) <> mix) then
     1036    // not already producing that
     1037    Result := Server(sSetCityProject, Me, cix, mix);
     1038end;
     1039
     1040function TCustomAI.City_StartEmigration(cix, mix: Integer;
     1041  AllowDisbandCity, AsConscripts: Boolean): Integer;
     1042var
     1043  NewProject: Integer;
    10111044begin
    10121045  NewProject := mix;
    1013   if AllowDisbandCity then NewProject := NewProject or cpDisbandCity;
    1014   if AsConscripts then NewProject := NewProject or cpConscripts;
    1015   Result := Server(sSetCityProject, me, cix, NewProject);
    1016 end;
    1017 
    1018 function TCustomAI.City_StartImprovement(cix, iix: integer): integer;
    1019 var
    1020   NewProject: integer;
     1046  if AllowDisbandCity then
     1047    NewProject := NewProject or cpDisbandCity;
     1048  if AsConscripts then
     1049    NewProject := NewProject or cpConscripts;
     1050  Result := Server(sSetCityProject, Me, cix, NewProject);
     1051end;
     1052
     1053function TCustomAI.City_StartImprovement(cix, iix: Integer): Integer;
     1054var
     1055  NewProject: Integer;
    10211056begin
    10221057  NewProject := iix + cpImp;
    1023   Result := Server(sSetCityProject, me, cix, NewProject);
    1024 end;
    1025 
    1026 function TCustomAI.City_Improvable(cix, iix: integer): boolean;
    1027 var
    1028   NewProject: integer;
     1058  if (MyCity[cix].Project and (cpImp + cpIndex) <> NewProject) then
     1059    // not already producing that
     1060    Result := Server(sSetCityProject, Me, cix, NewProject);
     1061end;
     1062
     1063function TCustomAI.City_Improvable(cix, iix: Integer): Boolean;
     1064var
     1065  NewProject: Integer;
    10291066begin
    10301067  NewProject := iix + cpImp;
    1031   Result := Server(sSetCityProject - sExecute, me, cix, NewProject) >= rExecuted;
    1032 end;
    1033 
    1034 function TCustomAI.City_StopProduction(cix: integer): integer;
    1035 var
    1036   NewProject: integer;
     1068  Result := Server(sSetCityProject - sExecute, Me, cix, NewProject) >= rExecuted;
     1069end;
     1070
     1071function TCustomAI.City_StopProduction(cix: Integer): Integer;
     1072var
     1073  NewProject: Integer;
    10371074begin
    10381075  NewProject := imTrGoods + cpImp;
    1039   Result := Server(sSetCityProject, me, cix, NewProject);
    1040 end;
    1041 
    1042 function TCustomAI.City_BuyProject(cix: integer): integer;
    1043 begin
    1044   Result := Server(sBuyCityProject, me, cix, nodata^);
    1045 end;
    1046 
    1047 function TCustomAI.City_SellImprovement(cix, iix: integer): integer;
    1048 begin
    1049   Result := Server(sSellCityImprovement, me, cix, iix);
    1050 end;
    1051 
    1052 function TCustomAI.City_RebuildImprovement(cix, iix: integer): integer;
    1053 begin
    1054   Result := Server(sRebuildCityImprovement, me, cix, iix);
    1055 end;
    1056 
    1057 function TCustomAI.City_SetTiles(cix, NewTiles: integer): integer;
    1058 begin
    1059   Result := Server(sSetCityTiles, me, cix, NewTiles);
    1060 end;
    1061 
    1062 procedure TCustomAI.City_OptimizeTiles(cix: integer; ResourceWeights: integer);
     1076  Result := Server(sSetCityProject, Me, cix, NewProject);
     1077end;
     1078
     1079function TCustomAI.City_BuyProject(cix: Integer): Integer;
     1080begin
     1081  Result := Server(sBuyCityProject, Me, cix, nodata^);
     1082end;
     1083
     1084function TCustomAI.City_SellImprovement(cix, iix: Integer): Integer;
     1085begin
     1086  Result := Server(sSellCityImprovement, Me, cix, iix);
     1087end;
     1088
     1089function TCustomAI.City_RebuildImprovement(cix, iix: Integer): Integer;
     1090begin
     1091  Result := Server(sRebuildCityImprovement, Me, cix, iix);
     1092end;
     1093
     1094function TCustomAI.City_SetTiles(cix, NewTiles: Integer): Integer;
     1095begin
     1096  Result := Server(sSetCityTiles, Me, cix, NewTiles);
     1097end;
     1098
     1099procedure TCustomAI.City_OptimizeTiles(cix: Integer; ResourceWeights: Cardinal);
    10631100var
    10641101  Advice: TCityTileAdviceData;
    10651102begin
    10661103  Advice.ResourceWeights := ResourceWeights;
    1067   Server(sGetCityTileAdvice, me, cix, Advice);
     1104  Server(sGetCityTileAdvice, Me, cix, Advice);
    10681105  City_SetTiles(cix, Advice.Tiles);
    10691106end;
    10701107
    1071 
    10721108// negotiation
    1073 function TCustomAI.Nego_CheckMyAction: integer;
    1074 begin
    1075   assert(Opponent >= 0); // only allowed in negotiation mode
    1076   assert((MyAction = scDipNotice) or (MyAction = scDipAccept) or
     1109function TCustomAI.Nego_CheckMyAction: Integer;
     1110begin
     1111  Assert(Opponent >= 0); // only allowed in negotiation mode
     1112  Assert((MyAction = scDipNotice) or (MyAction = scDipAccept) or
    10771113    (MyAction = scDipCancelTreaty) or (MyAction = scDipOffer) or (MyAction = scDipBreak));
    1078   if MyAction = scDipOffer then Result := Server(MyAction - sExecute, me, 0, MyOffer)
     1114  if MyAction = scDipOffer then
     1115    Result := Server(MyAction - sExecute, Me, 0, MyOffer)
    10791116  else
    1080     Result := Server(MyAction - sExecute, me, 0, nodata^);
    1081 end;
    1082 
     1117    Result := Server(MyAction - sExecute, Me, 0, nodata^);
     1118end;
    10831119
    10841120initialization
    1085   nodata := pointer(0);
     1121  nodata := Pointer(0);
    10861122  RWDataSize := 0;
    10871123
  • trunk/AI Template/Names.pas

    r582 r583  
    44
    55uses
    6 Protocol;
     6  Protocol;
    77
    88const
    9 
    10 Name_Advance: array[0..nAdv-1] of string=
    11 ('Advanced Flight',
    12 'Amphibious Warfare',
    13 'Astronomy',
    14 'Atomic Theory',
    15 'Automobile',
    16 'Ballistics',
    17 'Banking',
    18 'Bridge Building',
    19 'Bronze Working',
    20 'Ceremonial Burial',
    21 'Chemistry',
    22 'Chivalry',
    23 'Composites',
    24 'Code of Laws',
    25 'Combined Arms',
    26 'Combustion Engine',
    27 'Communism',
    28 'Computers',
    29 'Conscription',
    30 'Construction',
    31 'The Corporation',
    32 'Space Flight',
    33 'Currency',
    34 'Democracy',
    35 'Economics',
    36 'Electricity',
    37 'Electronics',
    38 'Engineering',
    39 'Environmentalism',
    40 'The Wheel',
    41 'Explosives',
    42 'Flight',
    43 'Intelligence',
    44 'Gunpowder',
    45 'Horseback Riding',
    46 'Impulse Drive',
    47 'Industrialization',
    48 'Intelligent Arms',
    49 'Invention',
    50 'Iron Working',
    51 'The Laser',
    52 'Nuclear Power',
    53 'Literature',
    54 'Internet',
    55 'Magnetism',
    56 'Map Making',
    57 'Masonry',
    58 'Mass Production',
    59 'Mathematics',
    60 'Medicine',
    61 'Metallurgy',
    62 'Miniaturization',
    63 'Mobile Warfare',
    64 'Monarchy',
    65 'Mysticism',
    66 'Navigation',
    67 'Nuclear Fission',
    68 'Philosophy',
    69 'Physics',
    70 'Plastics',
    71 'Poetry',
    72 'Pottery',
    73 'Radio Communication',
    74 'Recycling',
    75 'Refrigeration',
    76 'Monotheism',
    77 'The Republic',
    78 'Robotics',
    79 'Rocketry',
    80 'Railroad',
    81 'Sanitation',
    82 'Science',
    83 'Writing',
    84 'Seafaring',
    85 'Self-Contained Environment',
    86 'Stealth',
    87 'Steam Engine',
    88 'Steel',
    89 'Synthetic Food',
    90 'Tactics',
    91 'Theology',
    92 'Theory of Gravity',
    93 'Trade',
    94 'Transstellar Colonization',
    95 'University',
    96 'Advanced Rocketry',
    97 'Warrior Code',
    98 'Alphabet',
    99 'Polytheism',
    100 'Refining',
    101 'Computing Technology',
    102 'Nano Technology',
    103 'Material Technology',
    104 'Artificial Intelligence');
    105 
    106 Name_Improvement: array[0..nImp-1] of string=
    107 ('The Pyramids',
    108 'The Temple of Zeus',
    109 'The Hanging Gardens',
    110 'The Colossus',
    111 'The Lighthouse',
    112 'The Great Library',
    113 'The Oracle',
    114 'Sun Tzu''s War Academy',
    115 'Leonardo''s Workshop',
    116 'Magellan''s Expedition',
    117 'Michelangelo''s Chapel',
    118 '*',
    119 'Newton''s College',
    120 'Bach''s Cathedral',
    121 '*',
    122 'The Statue of Liberty',
    123 'The Eiffel Tower',
    124 'The Hoover Dam',
    125 'The Shinkansen Express',
    126 'The Manhattan Project',
    127 'MIR Space Station',
    128 '*',
    129 '*',
    130 '*',
    131 '*',
    132 '*',
    133 '*',
    134 '*',
    135 'Trade Goods',
    136 'Barracks',
    137 'Granary',
    138 'Temple',
    139 'Marketplace',
    140 'Library',
    141 'Courthouse',
    142 'City Walls',
    143 'Aqueduct',
    144 'Bank',
    145 'Cathedral',
    146 'University',
    147 'Harbor',
    148 'Theater',
    149 'Factory',
    150 'Manufacturing Plant',
    151 'Recycling Center',
    152 'Power Station',
    153 'Hydroelectric Dam',
    154 'Nuclear Plant',
    155 'Offshore Platform',
    156 'Town Hall',
    157 'Sewer System',
    158 'Supermarket',
    159 'Superhighways',
    160 'Research Lab',
    161 'SAM Missile Battery',
    162 'Coastal Fortress',
    163 'Airport',
    164 'Dockyard',
    165 'Palace',
    166 'Great Wall',
    167 'Colosseum',
    168 'Observatory',
    169 'Military Academy',
    170 'Command Bunker',
    171 'Algae Plant',
    172 'Stock Exchange',
    173 'Space Port',
    174 'Colony Ship Component',
    175 'Power Module',
    176 'Habitation Module');
    177 
    178 Name_Feature: array[0..nFeature-1] of string=
    179 ('Weapons',
    180 'Armor',
    181 'Mobility',
    182 'Sea Transport',
    183 'Carrier',
    184 'Turbines',
    185 'Bombs',
    186 'Fuel',
    187 'Air Transport',
    188 'Navigation',
    189 'Radar / Sonar',
    190 'Submarine',
    191 'Artillery',
    192 'Alpine',
    193 'Supply Ship',
    194 'Overweight',
    195 'Air Defence',
    196 'Spy Plane',
    197 'Steam Power',
    198 'Nuclear Power',
    199 'Jet Engines',
    200 'Stealth',
    201 'Fanatic',
    202 'First Strike',
    203 'Power of Will',
    204 'Academy Training',
    205 'Line Production');
    206 
    207 Name_TerrainType: array[0..11] of string=
    208 ('Ocean',
    209 'Coast',
    210 'Grassland',
    211 'Desert',
    212 'Prairie',
    213 'Tundra',
    214 'Arctic',
    215 'Swamp',
    216 '*',
    217 'Forest',
    218 'Hills',
    219 'Mountains');
    220 
    221 Name_Government: array[0..nGov-1] of string=
    222 ('Anarchy',
    223 'Despotism',
    224 'Monarchy',
    225 'Republic',
    226 'Fundamentalism',
    227 'Communism',
    228 'Democracy',
    229 'Future Society');
     9  Name_Advance: array[0..nAdv - 1] of string =
     10    ('Advanced Flight',
     11    'Amphibious Warfare',
     12    'Astronomy',
     13    'Atomic Theory',
     14    'Automobile',
     15    'Ballistics',
     16    'Banking',
     17    'Bridge Building',
     18    'Bronze Working',
     19    'Ceremonial Burial',
     20    'Chemistry',
     21    'Chivalry',
     22    'Composites',
     23    'Code of Laws',
     24    'Combined Arms',
     25    'Combustion Engine',
     26    'Communism',
     27    'Computers',
     28    'Conscription',
     29    'Construction',
     30    'The Corporation',
     31    'Space Flight',
     32    'Currency',
     33    'Democracy',
     34    'Economics',
     35    'Electricity',
     36    'Electronics',
     37    'Engineering',
     38    'Environmentalism',
     39    'The Wheel',
     40    'Explosives',
     41    'Flight',
     42    'Intelligence',
     43    'Gunpowder',
     44    'Horseback Riding',
     45    'Impulse Drive',
     46    'Industrialization',
     47    'Intelligent Arms',
     48    'Invention',
     49    'Iron Working',
     50    'The Laser',
     51    'Nuclear Power',
     52    'Literature',
     53    'Internet',
     54    'Magnetism',
     55    'Map Making',
     56    'Masonry',
     57    'Mass Production',
     58    'Mathematics',
     59    'Medicine',
     60    'Metallurgy',
     61    'Miniaturization',
     62    'Mobile Warfare',
     63    'Monarchy',
     64    'Mysticism',
     65    'Navigation',
     66    'Nuclear Fission',
     67    'Philosophy',
     68    'Physics',
     69    'Plastics',
     70    'Poetry',
     71    'Pottery',
     72    'Radio Communication',
     73    'Recycling',
     74    'Refrigeration',
     75    'Monotheism',
     76    'The Republic',
     77    'Robotics',
     78    'Rocketry',
     79    'Railroad',
     80    'Sanitation',
     81    'Science',
     82    'Writing',
     83    'Seafaring',
     84    'Self-Contained Environment',
     85    'Stealth',
     86    'Steam Engine',
     87    'Steel',
     88    'Synthetic Food',
     89    'Tactics',
     90    'Theology',
     91    'Theory of Gravity',
     92    'Trade',
     93    'Transstellar Colonization',
     94    'University',
     95    'Advanced Rocketry',
     96    'Warrior Code',
     97    'Alphabet',
     98    'Polytheism',
     99    'Refining',
     100    'Computing Technology',
     101    'Nano Technology',
     102    'Material Technology',
     103    'Artificial Intelligence');
     104
     105  Name_Improvement: array[0..nImp - 1] of string =
     106    ('The Pyramids',
     107    'The Temple of Zeus',
     108    'The Hanging Gardens',
     109    'The Colossus',
     110    'The Lighthouse',
     111    'The Great Library',
     112    'The Oracle',
     113    'Sun Tzu''s War Academy',
     114    'Leonardo''s Workshop',
     115    'Magellan''s Expedition',
     116    'Michelangelo''s Chapel',
     117    '*',
     118    'Newton''s College',
     119    'Bach''s Cathedral',
     120    '*',
     121    'The Statue of Liberty',
     122    'The Eiffel Tower',
     123    'The Hoover Dam',
     124    'The Shinkansen Express',
     125    'The Manhattan Project',
     126    'MIR Space Station',
     127    '*',
     128    '*',
     129    '*',
     130    '*',
     131    '*',
     132    '*',
     133    '*',
     134    'Trade Goods',
     135    'Barracks',
     136    'Granary',
     137    'Temple',
     138    'Marketplace',
     139    'Library',
     140    'Courthouse',
     141    'City Walls',
     142    'Aqueduct',
     143    'Bank',
     144    'Cathedral',
     145    'University',
     146    'Harbor',
     147    'Theater',
     148    'Factory',
     149    'Manufacturing Plant',
     150    'Recycling Center',
     151    'Power Station',
     152    'Hydroelectric Dam',
     153    'Nuclear Plant',
     154    'Offshore Platform',
     155    'Town Hall',
     156    'Sewer System',
     157    'Supermarket',
     158    'Superhighways',
     159    'Research Lab',
     160    'SAM Missile Battery',
     161    'Coastal Fortress',
     162    'Airport',
     163    'Dockyard',
     164    'Palace',
     165    'Great Wall',
     166    'Colosseum',
     167    'Observatory',
     168    'Military Academy',
     169    'Command Bunker',
     170    'Algae Plant',
     171    'Stock Exchange',
     172    'Space Port',
     173    'Colony Ship Component',
     174    'Power Module',
     175    'Habitation Module');
     176
     177  Name_Feature: array[0..nFeature - 1] of string =
     178    ('Weapons',
     179    'Armor',
     180    'Mobility',
     181    'Sea Transport',
     182    'Carrier',
     183    'Turbines',
     184    'Bombs',
     185    'Fuel',
     186    'Air Transport',
     187    'Navigation',
     188    'Radar / Sonar',
     189    'Submarine',
     190    'Artillery',
     191    'Alpine',
     192    'Supply Ship',
     193    'Overweight',
     194    'Air Defence',
     195    'Spy Plane',
     196    'Steam Power',
     197    'Nuclear Power',
     198    'Jet Engines',
     199    'Stealth',
     200    'Fanatic',
     201    'First Strike',
     202    'Power of Will',
     203    'Academy Training',
     204    'Line Production');
     205
     206  Name_TerrainType: array[0..11] of string =
     207    ('Ocean',
     208    'Coast',
     209    'Grassland',
     210    'Desert',
     211    'Prairie',
     212    'Tundra',
     213    'Arctic',
     214    'Swamp',
     215    '*',
     216    'Forest',
     217    'Hills',
     218    'Mountains');
     219
     220  Name_Government: array[0..nGov - 1] of string =
     221    ('Anarchy',
     222    'Despotism',
     223    'Monarchy',
     224    'Republic',
     225    'Fundamentalism',
     226    'Communism',
     227    'Democracy',
     228    'Future Society');
    230229
    231230implementation
    232231
    233232end.
    234 
  • trunk/AI Template/Pile.pas

    r582 r583  
    88interface
    99
    10 procedure Create(Size: integer);
     10procedure Create(Size: Integer);
    1111procedure Free;
    1212procedure Empty;
    13 function Put(Item, Value: integer): boolean;
    14 function TestPut(Item, Value: integer): boolean;
    15 function Get(var Item, Value: integer): boolean;
     13function Put(Item, Value: Integer): Boolean;
     14function TestPut(Item, Value: Integer): Boolean;
     15function Get(var Item, Value: Integer): Boolean;
    1616
    1717
     
    2323type
    2424  TheapItem = record
    25     Item: integer;
    26     Value: integer;
     25    Item: Integer;
     26    Value: Integer;
    2727  end;
    2828
    2929var
    3030  bh: array[0..MaxSize - 1] of TheapItem;
    31   Ix: array[0..MaxSize - 1] of integer;
    32   n, CurrentSize: integer;
    33   {$IFDEF DEBUG}InUse: boolean;{$ENDIF}
     31  Ix: array[0..MaxSize - 1] of Integer;
     32  N, CurrentSize: Integer;
     33{$IFDEF DEBUG}InUse: Boolean;{$ENDIF}
    3434
    3535
    36 procedure Create(Size: integer);
     36procedure Create(Size: Integer);
    3737begin
    3838  {$IFDEF DEBUG}
    39   assert(not InUse, 'Pile is a single instance class, ' +
     39  Assert(not InUse, 'Pile is a single instance class, ' +
    4040    'no multiple usage possible. Always call Pile.Free after use.');
    41   {$ENDIF}
    42   assert(Size <= MaxSize);
    43   if (n <> 0) or (Size > CurrentSize) then
     41{$ENDIF}
     42  Assert(Size <= MaxSize);
     43  if (N <> 0) or (Size > CurrentSize) then
    4444  begin
    45     FillChar(Ix, Size * sizeOf(integer), 255);
    46     n := 0;
     45    FillChar(Ix, Size * SizeOf(Integer), 255);
     46    N := 0;
    4747  end;
    4848  CurrentSize := Size;
    49   {$IFDEF DEBUG}
     49{$IFDEF DEBUG}
    5050  InUse := True;
    51   {$ENDIF}
     51{$ENDIF}
    5252end;
    5353
    5454procedure Free;
    5555begin
    56   {$IFDEF DEBUG}
    57   assert(InUse);
     56{$IFDEF DEBUG}
     57  Assert(InUse);
    5858  InUse := False;
    59   {$ENDIF}
     59{$ENDIF}
    6060end;
    6161
    6262procedure Empty;
    6363begin
    64   if n <> 0 then
     64  if N <> 0 then
    6565  begin
    66     FillChar(Ix, CurrentSize * sizeOf(integer), 255);
    67     n := 0;
     66    FillChar(Ix, CurrentSize * SizeOf(Integer), 255);
     67    N := 0;
    6868  end;
    6969end;
    7070
    71 //Parent(i) = (i-1)/2.
    72 function Put(Item, Value: integer): boolean; //O(lg(n))
     71// Parent(i) = (i-1)/2.
     72function Put(Item, Value: Integer): Boolean; // O(lg(n))
    7373var
    74   i, j: integer;
     74  I, J: Integer;
    7575begin
    76   assert(Item < CurrentSize);
    77   i := Ix[Item];
    78   if i >= 0 then
     76  Assert(Item < CurrentSize);
     77  I := Ix[Item];
     78  if I >= 0 then
    7979  begin
    80     if bh[i].Value <= Value then
     80    if bh[I].Value <= Value then
    8181    begin
    8282      Result := False;
    83       exit;
     83      Exit;
    8484    end;
    8585  end
    8686  else
    8787  begin
    88     i := n;
    89     Inc(n);
     88    I := N;
     89    Inc(N);
    9090  end;
    9191
    92   while i > 0 do
     92  while I > 0 do
    9393  begin
    94     j := (i - 1) shr 1;  //Parent(i) = (i-1)/2
    95     if Value >= bh[j].Value then  break;
    96     bh[i] := bh[j];
    97     Ix[bh[i].Item] := i;
    98     i := j;
     94    J := (I - 1) shr 1;  // Parent(i) = (i-1)/2
     95    if Value >= bh[J].Value then
     96      Break;
     97    bh[I] := bh[J];
     98    Ix[bh[I].Item] := I;
     99    I := J;
    99100  end;
    100   //  Insert the new Item at the insertion point found.
    101   bh[i].Value := Value;
    102   bh[i].Item := Item;
    103   Ix[bh[i].Item] := i;
     101  // Insert the new Item at the insertion point found.
     102  bh[I].Value := Value;
     103  bh[I].Item := Item;
     104  Ix[bh[I].Item] := I;
    104105  Result := True;
    105106end;
    106107
    107 function TestPut(Item, Value: integer): boolean;
     108function TestPut(Item, Value: Integer): Boolean;
    108109var
    109   i: integer;
     110  I: Integer;
    110111begin
    111   assert(Item < CurrentSize);
    112   i := Ix[Item];
    113   Result := (i < 0) or (bh[i].Value > Value);
     112  Assert(Item < CurrentSize);
     113  I := Ix[Item];
     114  Result := (I < 0) or (bh[I].Value > Value);
    114115end;
    115116
    116117//Left(i) = 2*i+1.
    117118//Right(i) = 2*i+2 => Left(i)+1
    118 function Get(var Item, Value: integer): boolean; //O(lg(n))
     119function Get(var Item, Value: Integer): Boolean; //O(lg(n))
    119120var
    120   i, j: integer;
    121   last: TheapItem;
     121  I, J: Integer;
     122  Last: TheapItem;
    122123begin
    123   if n = 0 then
     124  if N = 0 then
    124125  begin
    125126    Result := False;
    126     exit;
     127    Exit;
    127128  end;
    128129
     
    132133  Ix[Item] := -1;
    133134
    134   Dec(n);
    135   if n > 0 then
     135  Dec(N);
     136  if N > 0 then
    136137  begin
    137     last := bh[n];
    138     i := 0;
    139     j := 1;
    140     while j < n do
     138    Last := bh[N];
     139    I := 0;
     140    J := 1;
     141    while J < N do
    141142    begin
    142143      //  Right(i) = Left(i)+1
    143       if (j < n - 1) and (bh[j].Value > bh[j + 1].Value) then
    144         Inc(j);
    145       if last.Value <= bh[j].Value then  break;
     144      if (J < N - 1) and (bh[J].Value > bh[J + 1].Value) then
     145        Inc(J);
     146      if Last.Value <= bh[J].Value then
     147        Break;
    146148
    147       bh[i] := bh[j];
    148       Ix[bh[i].Item] := i;
    149       i := j;
    150       j := j shl 1 + 1;  //Left(j) = 2*j+1
     149      bh[I] := bh[J];
     150      Ix[bh[I].Item] := I;
     151      I := J;
     152      J := J shl 1 + 1;  //Left(j) = 2*j+1
    151153    end;
    152154
    153155    // Insert the root in the correct place in the heap.
    154     bh[i] := last;
    155     Ix[last.Item] := i;
     156    bh[I] := Last;
     157    Ix[Last.Item] := I;
    156158  end;
    157159  Result := True;
     
    159161
    160162initialization
    161   n := 0;
     163  N := 0;
    162164  CurrentSize := 0;
    163   {$IFDEF DEBUG}
     165{$IFDEF DEBUG}
    164166  InUse := False;
    165   {$ENDIF}
     167{$ENDIF}
    166168end.
  • trunk/AI Template/Switches.inc

    r582 r583  
    1010{$TYPEINFO OFF}
    1111{$DEBUGINFO ON}
    12 {$LOCALSYMBOLS ON}
     12//{$LOCALSYMBOLS ON}
    1313
    14 {$E-,S-,Z1}
     14//{$E-}
     15{$S-}
     16{$Z1}
    1517
    1618{$IFDEF FPC} // freepascal
  • trunk/AI/StdAI/Names.pas

    r289 r583  
    77
    88const
    9 
    109  Name_Advance: array[0..nAdv - 1] of string =
    1110    ('Advanced Flight',
  • trunk/AI/StdAI/Pile.pas

    r486 r583  
    163163  N := 0;
    164164  CurrentSize := 0;
    165         {$IFDEF DEBUG}
     165{$IFDEF DEBUG}
    166166  InUse := False;
    167167{$ENDIF}
  • trunk/AI/StdAI/Protocol.pas

    r447 r583  
    1111  nImp = 70; { number of improvements }
    1212  nPl = 15; { max number of players, don't change! }
    13   nWonder = 28; { max number of wonders }
     13  nWonder = 28; { number of wonders }
    1414  nUmax = 4096; { max units/player, don't set above 4096 }
    1515  nCmax = 1024; { max cities/player, don't set above 4096 }
     
    1818  ExpCost = 50; { received damage required for next experience level }
    1919  MaxFutureTech = 25;
    20   // maximum number of future techs of one kind except computing technology
     20  // Maximum number of future techs of one kind except computing technology
    2121  MaxFutureTech_Computing = 100;
    22   // maximum number of computing technology future techs
     22  // Maximum number of computing technology future techs
    2323  CountryRadius = 9;
    2424  MaxCitySize = 30;
     
    3636  CancelTreatyTurns = 3;
    3737  PeaceEvaTurns = 5;
    38   // should be less then 2*CancelTreatyTurns, so that you can't attack an ally without re-entering
     38  // Should be less then 2*CancelTreatyTurns, so that you can't attack an ally without re-entering
    3939  ColdWarTurns = 40;
    4040  DesertThurst = 20; // damage for turn in desert
     
    4949  InitialCredibility = 95;
    5050
    51   // ai module flags (for TInitModuleData.Flags)
     51  // AI module flags (for TInitModuleData.Flags)
    5252  aiThreaded = $01;
    5353
    54   // difficulty settings
     54  // Difficulty settings
    5555  MaxDiff = 4; { maximum difficulty level }
    5656  StorageSize: array [1 .. MaxDiff] of Integer = (30, 40, 50, 60);
     
    5959  BuildCostMod: array [1 .. MaxDiff] of Integer = (9, 12, 15, 18); // in 1/12
    6060
    61   // test flags
     61  // Test flags
    6262  nTestFlags = 7; // max. 11
    6363  tfAllTechs = $001; { all nations get all techs }
     
    7070  tfTested = $800; // at least one test flag was set
    7171
    72   { server commands
     72  { Server commands
    7373    IMPORTANT: lowest 4 bits must indicate size in DWORDS of data parameter,
    7474    except for request commands }
     
    191191  sSetCityTiles = $7201;
    192192
    193   // free command space
     193  // Free command space
    194194  sctUnused = $3800;
    195195
    196   { client commands }
     196  { Client commands }
    197197  cInitModule = $0000;
    198198  cReleaseModule = $0100;
     
    241241  cRefreshDebugMap = $3F90;
    242242
    243   // diplomacy commands equal to server, see below
     243  // Diplomacy commands equal to server, see below
    244244
    245245  cDebugMessage = $7000;
    246246  cShowNego = $7010;
    247247
    248   // commands same for server and client
     248  // Commands same for server and client
    249249  scContact = $4900; // + concerned player shl 4 for server call
    250250  scReject = $4A00;
     
    256256  scDipBreak = $4BF0;
    257257
    258   { server return codes: flags }
     258  { Server return codes: flags }
    259259  rExecuted = $40000000;
    260260  rEffective = $20000000;
     
    262262  rEnemySpotted = $08000000;
    263263
    264   { server return codes: command executed }
    265   // note: the same return code might have a different meaning for different server functions!
     264  { Server return codes: command executed }
     265  // Note: the same return code might have a different meaning for different server functions!
    266266  eOK = $60000000; // ok
    267267  eEnemySpotted = $68000000; // unit move ok, new enemy unit/city spotted
    268268  eDied = $70000000; // move executed, unit died due to hostile terrain
    269269  eEnemySpotted_Died = $78000000;
    270   // unit move ok, new enemy unit/city spotted, unit died due to hostile terrain
     270  // Unit move ok, new enemy unit/city spotted, unit died due to hostile terrain
    271271  eLoaded = $60000002; // unit move caused loading to transport ship
    272272  eLost = $70000004; // attack executed, battle lost, unit is dead
     
    276276  eExpelled = $60000007; // friendly unit expelled
    277277  eMissionDone = $70000008;
    278   // spy moved into city: mission done, spy no longer exists
     278  // Spy moved into city: mission done, spy no longer exists
    279279  eJobDone = $60000001; // settler job started and already done
    280280  eJobDone_Died = $70000001;
    281   // settler job started and already done, unit died due to hostile terrain
     281  // Settler job started and already done, unit died due to hostile terrain
    282282  eCity = $70000002; // city founded, settler no more exists
    283283  eRemoved = $70000000; // sRemoveUnit: unit removed
     
    285285
    286286  eNotChanged = $40000000;
    287   // ok, but no effect (e.g. current city project set again)
    288 
    289   { server return codes: command not executed }
     287  // Ok, but no effect (e.g. current city project set again)
     288
     289  { Server return codes: command not executed }
    290290  eHiddenUnit = $20000013;
    291   // unit move: not possible, destination tile occupied by hidden foreign submarine
     291  // Unit move: not possible, destination tile occupied by hidden foreign submarine
    292292  eStealthUnit = $2000001A;
    293   // unit move: not possible, destination tile occupied by foreign stealth unit
     293  // Unit move: not possible, destination tile occupied by foreign stealth unit
    294294  eZOC_EnemySpotted = $28000014;
    295   // unit move: not possible, new enemy unit spotted, ZOC violation
     295  // Unit move: not possible, new enemy unit spotted, ZOC violation
    296296
    297297  eInvalid = $0000; // command not allowed now or parameter out of allowed range
     
    308308
    309309  eDomainMismatch = $0011;
    310   // move/attack: action not allowed for this unit domain
     310  // Move/attack: action not allowed for this unit domain
    311311  eNoCapturer = $0012;
    312   // unit move: this type of unit is not allowed to capture a city
     312  // Unit move: this type of unit is not allowed to capture a city
    313313  eZOC = $0014; // unit move: not possible, ZOC violation
    314314  eTreaty = $0015; // move/attack: not possible, peace treaty violation
     
    320320
    321321  eMaxSize = $0020;
    322   // add to city: bigger size not allowed due to missing aqueduct/sewer
     322  // Add to city: bigger size not allowed due to missing aqueduct/sewer
    323323  eNoCityTerrain = $0022; // found city: not possible in this terrain
    324324  eNoBridgeBuilding = $0023;
     
    332332  eNoWorkerAvailable = $0051;
    333333  eOnlyOnce = $0058;
    334   // sell/rebuild city improvement: only once per city and turn!
     334  // Sell/rebuild city improvement: only once per city and turn!
    335335  eObsolete = $0059; // city project: more advanced improvement already exists
    336336  eOutOfControl = $005A;
    337   // buy/sell/rebuild improvement: not in anarchy, not in captured cities
     337  // Buy/sell/rebuild improvement: not in anarchy, not in captured cities
    338338
    339339  eNoWay = $0100; // sGetMoveAdvice: no way found
    340340
    341   // chart types
     341  // Chart types
    342342  nStat = 6;
    343343  stPop = 0;
     
    348348  stWork = 5;
    349349
    350   { tile flags: terrain type }
     350  { Tile flags: terrain type }
    351351  fTerrain = $1F; // mask for terrain type
    352352  fOcean = $00;
     
    363363  fUNKNOWN = fTerrain;
    364364
    365   { tile flags: terrain improvements }
     365  { Tile flags: terrain improvements }
    366366  fTerImp = $0000F000; // mask for terrain improvement
    367367  tiNone = $00000000;
     
    372372  tiBase = $00005000;
    373373
    374   { tile flags: add ons }
     374  { Tile flags: add ons }
    375375  fSpecial = $00000060;
    376376  fSpecial1 = $00000020;
     
    378378  fRiver = $00000080;
    379379  fRoad = $00000100;
    380   fRR = $00000200;
     380  fRR = $00000200; // railroad
    381381  fCanal = $00000400;
    382382  fPoll = $00000800;
     
    389389  fMercury = $06000000;
    390390
    391   { tile flags: redundant helper info }
     391  { Tile flags: redundant helper info }
    392392  fGrWall = $00010000; // tile protected by great wall
    393393  fSpiedOut = $00020000;
     
    400400  fOwnZoCUnit = $10000000; // own ZoC unit present at this tile
    401401  fInEnemyZoC = $20000000;
    402   // tile is adjacent to known foreign ZoC unit (not allied)
     402  // Tile is adjacent to known foreign ZoC unit (not allied)
    403403  fPeace = $40000000;
    404404  // tile belongs to territory of nation that we are in peace with but not allied
    405405
    406   // city project flags
     406  // City project flags
    407407  cpIndex = $1FF;
    408408  cpConscripts = $200; // produce unit as conscripts
    409409  cpDisbandCity = $400;
    410   // allow to disband city when settlers/conscripts are produced
     410  // Allow to disband city when settlers/conscripts are produced
    411411  cpImp = $800; // 0: index refers to model, 1: index refers to city improvement
    412412  cpRepeat = $1000;
     
    414414  cpAuto = $F000; // for internal use only
    415415
    416   // tech status indicators
     416  // Tech status indicators
    417417  tsNA = -2;
    418418  tsSeen = -1;
     
    422422  tsApplicable = tsResearched;
    423423
    424   // nation treaties
     424  // Nation treaties
    425425  trNoContact = -1;
    426426  trNone = 0;
     
    429429  trAlliance = 4;
    430430
    431   // attitudes
     431  // Attitudes
    432432  nAttitude = 7;
    433433  atHostile = 0;
     
    439439  atEnth = 6;
    440440
    441   // offer prices
     441  // Offer prices
    442442  opChoose = $00000000;
    443443  opCivilReport = $11000000; // + turn + concerned player shl 16
     
    455455  opMask = $FF000000;
    456456
    457   // improvement kinds
     457  // Improvement kinds
    458458  ikTrGoods = 0;
    459459  ikCommon = 1;
     
    464464  ikNA = $7F;
    465465
    466   { model domains }
     466  { Model domains }
    467467  nDomains = 3;
    468468  dGround = 0;
     
    470470  dAir = 2;
    471471
    472   { model kinds }
     472  { Model kinds }
    473473  mkSelfDeveloped = $00;
    474474  mkEnemyDeveloped = $01;
     
    483483  mkFreight = $24;
    484484
    485   { unit flags }
     485  { Unit flags }
    486486  unFortified = $01;
    487487  unBombsLoaded = $02;
     
    491491  unMulti = $80;
    492492
    493   // unit report flags
     493  // Unit report flags
    494494  urfAlwaysSupport = $01;
    495495  urfDeployed = $02;
    496496
    497   // unit moves
     497  // Unit moves
    498498  umCapturing = $0100;
    499499  umSpyMission = $0200;
     
    505505  umPlaneUnloading = $8000;
    506506
    507   { model flags }
     507  { Model flags }
    508508  mdZOC = $01;
    509509  mdCivil = $02;
    510510  mdDoubleSupport = $04;
    511511
    512   { player happened flags }
     512  { Player happened flags }
    513513  phTech = $01;
    514514  phStealTech = $02;
     
    523523  phGameEnd = $F000;
    524524
    525   { city happened flags }
     525  { City happened flags }
    526526  chDisorder = $01;
    527527  chProduction = $02;
     
    541541  chImprovementSold = $80000000;
    542542
    543   { city info flags }
     543  { City info flags }
    544544  ciCapital = $01;
    545545  ciWalled = $02;
     
    549549  ciSpacePort = $20;
    550550
    551   { city tile available values }
     551  { City tile available values }
    552552  faAvailable = 0;
    553553  faNotAvailable = 1;
     
    556556  faInvalid = $FF;
    557557
    558   // battle history flags
     558  // Battle history flags
    559559  bhEnemyAttack = $01;
    560560  bhMyUnitLost = $02;
    561561  bhEnemyUnitLost = $04;
    562562
    563   { move advice special destinations }
     563  { Move advice special destinations }
    564564  maNextCity = -1;
    565565
    566   { goverment forms }
     566  { Goverment forms }
    567567  nGov = 8;
    568568  gAnarchy = 0;
     
    575575  gFuture = 7;
    576576
    577   // ship change reasons
     577  // Ship change reasons
    578578  scrProduction = 0;
    579579  scrDestruction = 1;
     
    581581  scrCapture = 3;
    582582
    583   { unit jobs }
     583  { Unit jobs }
    584584  nJob = 15;
    585585  jNone = 0;
     
    599599  jCity = 14;
    600600
    601   // job preconditions are:
     601  // Job preconditions are:
    602602  // technology JobPreq is available, no city, plus the following:
    603603  // jRoad: no river when bridge building unavailable
     
    614614  // jCity, jFort, jBase: none
    615615
    616   // spy mission
     616  // Spy mission
    617617  nSpyMission = 5;
    618618  smSabotageProd = 0;
     
    622622  smStealMilReport = 4;
    623623
    624   // resource weights
     624  // Resource weights
    625625  rwOff = $00000000;
    626626  rwMaxGrowth = $3F514141; // 120*F + 1/8*P + 1/16*T + 1/16*S
     
    630630  rwForceScience = $F1010101; // F^1/2 * (1*P + 1*T + 1*S)
    631631
    632   { advances }
     632  { Advances }
    633633  adAdvancedFlight = 0;
    634634  adAmphibiousWarfare = 1;
     
    731731  adMilitary = $800; // Military Research
    732732
    733   { wonders }
     733  { Wonders }
    734734  woPyramids = 00;
    735735  woZeus = 01;
     
    752752  woMir = 20;
    753753
    754   { city improvements }
     754  { City improvements }
    755755  imTrGoods = 28;
    756756  imBarracks = 29;
     
    801801  // in 1/2*city size
    802802
    803   // special prerequisite values
     803  // Special prerequisite values
    804804  preNone = -1;
    805805  preLighthouse = -2;
     
    813813    adExplosives, adConstruction, preNone, adMedicine, preNone, preNone);
    814814
    815   AdvPreq: array [0 .. nAdv - 1, 0 .. 2] of Integer = { advance prerequisites }
     815  AdvPreq: array [0 .. nAdv - 1, 0 .. 2] of Integer = { Advance prerequisites }
    816816    ((adFlight, adRobotics, preNone), // adAdvancedFlight
    817817    (adNavigation, adTactics, preNone), // adAmphibiousWarfare
     
    910910    (adSmartWeapons, preNone, preNone)); // futMissileTechnology
    911911
    912 Imp: array [0 .. nImp - 1] of // city improvements
     912Imp: array [0 .. nImp - 1] of // City improvements
    913913record
    914914  Kind: Integer;
     
    10191019  (NewImp: imMilAcademy; OldImp: imBarracks));
    10201020
    1021 // colony ship
     1021// Colony ship
    10221022nShipPart = 3;
    10231023spComp = 0;
     
    10991099  TradeRes: (0, 0, 7); Filler: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))); { Mou }
    11001100
    1101 // settler work required MP
     1101// Settler work required MP
    11021102PillageWork = 100;
    11031103CityWork = 900;
     
    11121112PollWork = 1800;
    11131113
    1114 // upgrades for new unit models
     1114// Upgrades for new unit models
    11151115// upgrade[domain,0].preq is domain precondition advance
    11161116// cost values accumulate if prerequisite is future tech / are maximized if not
    11171117nUpgrade = 15;
    1118 upgrade: array [0 .. nDomains - 1, 0 .. nUpgrade - 1] of record
     1118Upgrade: array [0..nDomains - 1, 0..nUpgrade - 1] of record
    11191119  Preq: Integer;
    11201120  Strength: Integer;
     
    11681168  (Preq: preNA; Strength: 0; Trans: 0; Cost: 0)));
    11691169
    1170 { model features }
     1170{ Model features }
    11711171nFeature = 27;
    11721172mcWeapons = 0;
     
    12001200AutoFeature: set of mcFirstNonCap .. nFeature - 1 = [mcNav, mcSE, mcNP, mcJet,
    12011201  mcAcademy];
    1202 // unit class advances, automatically applied if available
    1203 
    1204 Feature: array [0 .. nFeature - 1] of { unit model features }
     1202// Unit class advances, automatically applied if available
     1203
     1204Feature: array [0 .. nFeature - 1] of { Unit model features }
    12051205  record
    12061206    Domains: Integer;
     
    12431243INFIN = 999999;
    12441244
    1245 // for backward compatibility
     1245// For backward compatibility
    12461246fRare = fDeadLands;
    12471247fRare1 = fCobalt;
     
    12751275  TClientCall = procedure (Command, Player: Integer; var Data); stdcall;
    12761276
     1277  TCommand = (
     1278    cmInitModule = $0000,
     1279    cmReleaseModule = $0100,
     1280    cmBroadcast = $0200,
     1281    cmHelpOnly = $0700,
     1282    cmStartHelp = $0710,
     1283    cmStartCredits = $0720,
     1284
     1285    cmNewGame = $0800,
     1286    cmLoadGame = $0810,
     1287    cmMovie = $0820,
     1288    cmNewGameEx = $0840,
     1289    cmLoadGameEx = $0850,
     1290    cmNewMap = $0880,
     1291    cmReplay = $08E0,
     1292    cmGetReady = $08F0,
     1293    cmBreakGame = $0900,
     1294
     1295    cmTurn = $2000,
     1296    cmResume = $2010,
     1297    cmContinue = $2080,
     1298    cmMovieTurn = $2100,
     1299    cmMovieEndTurn = $2110,
     1300    cmEditMap = $2800,
     1301
     1302    // cShowTileM=$3000;cShowTileA=$3010;cShowFoundCity=$3020;
     1303    cmShowUnitChanged = $3030,
     1304    cmShowAfterMove = $3040,
     1305    cmShowAfterAttack = $3050,
     1306    cmShowCityChanged = $3090,
     1307    // cShowMove=$3100;cShowCapture=$3110;
     1308    // cShowAttackBegin=$3200;cShowAttackWon=$3210;cShowAttackLost=$3220;
     1309    cmShowMoving = $3140,
     1310    cmShowCapturing = $3150,
     1311    cmShowAttacking = $3240,
     1312    cmShowMissionResult = $3300,
     1313    cmShowShipChange = $3400,
     1314    cmShowGreatLibTech = $3500,
     1315    cmShowTurnChange = $3700,
     1316    cmShowCancelTreaty = $3800,
     1317    cmShowEndContact = $3810,
     1318    cmShowCancelTreatyByAlliance = $3820,
     1319    cmShowSupportAllianceAgainst = $3830,
     1320    cmShowPeaceViolation = $3880,
     1321    cmShowGame = $3F00, { cShowSuperView=$3F80; }
     1322    cmRefreshDebugMap = $3F90,
     1323
     1324    // Diplomacy commands equal to server, see below
     1325
     1326    cmDebugMessage = $7000,
     1327    cmShowNego = $7010
     1328  );
     1329
    12771330  TUn = packed record
    12781331    Loc: LongInt; { location }
     
    13321385    Cost: Word;
    13331386    MStrength: Word;
    1334     // construction time multipliers, only valid if kind is mkSelfDeveloped or mkEnemyDeveloped
     1387    // Construction time multipliers, only valid if kind is mkSelfDeveloped or mkEnemyDeveloped
    13351388    MTrans: Byte;
    13361389    MCost: Byte;
    13371390    Weight: Byte;
    13381391    MaxWeight: Byte;
    1339     // weight and maximum weight (construction time)
     1392    // Weight and maximum weight (construction time)
    13401393    Upgrades: Cardinal; // bitarray indicating all upgrades
    13411394    Flags: Cardinal;
     
    14721525  TCityReportNew = record
    14731526    HypoTiles: Integer;
    1474     // tiles that should be considered as exploited (for the current adjustment, set this to -1 or to TCity.Tiles of the city)
     1527    // Tiles that should be considered as exploited (for the current adjustment, set this to -1 or to TCity.Tiles of the city)
    14751528    HypoTaxRate: Integer;
    14761529    HypoLuxuryRate: Integer;
    1477     // tax and luxury rate that should be assumed (for current rates, set this to -1 or to RO.TaxRate resp. RO.LuxRate)
     1530    // Tax and luxury rate that should be assumed (for current rates, set this to -1 or to RO.TaxRate resp. RO.LuxRate)
    14781531    Morale: Integer;
    14791532    FoodSupport: Integer;
    14801533    MaterialSupport: Integer;
    1481     // food and material taken for unit support
     1534    // Food and material taken for unit support
    14821535    ProjectCost: Integer; // material cost of current project
    14831536    Storage: Integer; // size of food storage
     
    14871540    CollectedMaterial: Integer;
    14881541    CollectedTrade: Integer;
    1489     // raw control, food, material and trade as collected by the citizens
     1542    // Raw control, food, material and trade as collected by the citizens
    14901543    Working: Integer; // number of exploited tiles including city tile
    14911544    FoodSurplus: Integer;
    14921545    Production: Integer;
    14931546    AddPollution: Integer;
    1494     // food surplus, production gain and pollution after all effects
     1547    // Food surplus, production gain and pollution after all effects
    14951548    Corruption: Integer;
    14961549    Tax: Integer;
    14971550    Science: Integer;
    14981551    Luxury: Integer;
    1499     // corruption, tax, science and wealth after all effects
     1552    // Corruption, tax, science and wealth after all effects
    15001553    HappinessBalance: Integer;
    15011554    // = (Morale+Wealth+Control) - (Size+Unrest), value < 0 means disorder
     
    15471600    Movement: Integer;
    15481601    EndHealthDef: Integer;
    1549     EndHealthAtt: Integer; // must be same as in TBattleForecast
     1602    EndHealthAtt: Integer; // Must be same as in TBattleForecast
    15501603    AStr: Integer;
    15511604    DStr: Integer;
     
    16121665    Data: Pointer;
    16131666    Map: ^TTileList;
    1614     { the playground, a list of tiles with index = location, see tile flags }
     1667    { The playground, a list of tiles with index = location, see tile flags }
    16151668    MapObservedLast: ^TTileObservedLastList;
    1616     // turn in which the tile was observed last, index = location
     1669    // Turn in which the tile was observed last, index = location
    16171670    Territory: ^TOwnerList; // nation to which's territory a tile belongs, -1 indicates none
    16181671    Un: ^TUnList; { units }
     
    16421695    LuxRate: Integer;
    16431696    Research: Integer;
    1644     { collected research points for currently researched tech }
     1697    { Collected research points for currently researched tech }
    16451698    ResearchTech: Integer; // currently researched tech
    16461699    DevModel: TModel; { unit model currently under development }
     
    16691722    Flags: Integer;
    16701723  end;
     1724  PInitModuleData = ^TInitModuleData;
    16711725
    16721726  TNewGameData = record
    1673     lx: Integer;
    1674     ly: Integer;
     1727    lx: Integer; // Map width
     1728    ly: Integer; // Map height
    16751729    LandMass: Integer;
    16761730    MaxTurn: Integer;
    16771731    Difficulty: array [0 .. nPl - 1] of Integer;
    1678     { difficulty levels of the players, if it's 0 this player is the supervisor,
     1732    { Difficulty levels of the players, if it's 0 this player is the supervisor,
    16791733      -1 for unused slots }
    16801734    RO: array [0 .. nPl - 1] of ^TPlayerContext;
     
    16901744    RND: Integer;
    16911745    Difficulty: array [0 .. nPl - 1] of Integer;
    1692     { difficulty levels of the players, if it's 0 this player is the supervisor,
     1746    { Difficulty levels of the players, if it's 0 this player is the supervisor,
    16931747      -1 for unused slots }
    16941748    Controlled: Integer;
     
    17031757
    17041758const
    1705   { predefined unit models: }
     1759  { Predefined unit models: }
    17061760  nSpecialModel = 9;
    17071761  SpecialModel: array [0 .. nSpecialModel - 1] of TModel = ((Status: 0;
     
    17771831function DelphiRandom: Extended; overload;
    17781832procedure DelphiRandomize;
     1833function GetCommandDataSize(Command: TCommand): Integer;
    17791834
    17801835
     
    18031858  mi.Domain := M.Domain;
    18041859  if M.Kind = mkEnemyDeveloped then
    1805     mi.Kind := mkSelfDeveloped // important for IsSameModel()
     1860    mi.Kind := mkSelfDeveloped // Important for IsSameModel()
    18061861  else
    18071862    mi.Kind := M.Kind;
     
    18561911    Y := Loc div lx;
    18571912    X := Loc - Y * lx;
    1858     if TerrType = fGrass then { formula for productive grassland }
     1913    if TerrType = fGrass then { Formula for productive grassland }
    18591914      if Odd((lymax + X - Y shr 1) shr 1 + X + (Y + 1) shr 1) then
    18601915        Result := 1
    18611916      else
    18621917        Result := 0
    1863     else { formula for special resources }
     1918    else { Formula for special resources }
    18641919    begin
    18651920      A := 4 * X - Y + 9980;
     
    18881943      else
    18891944        Result := 0;
    1890     end
     1945    end;
    18911946  end;
    18921947end;
     
    19191974end;
    19201975
     1976function GetCommandDataSize(Command: TCommand): Integer;
     1977begin
     1978  case Command of
     1979    cmInitModule: Result := SizeOf(TInitModuleData);
     1980    cmGetReady: Result := 0;
     1981    cmTurn: Result := 0;
     1982    cmShowTurnChange: Result := SizeOf(Integer);
     1983    cmShowNego: Result := SizeOf(TShowNegoData);
     1984    cmNewGame, cmLoadGame, cmMovie, cmNewMap: Result := SizeOf(TNewGameData);
     1985    cmShowShipChange: Result := SizeOf(TShowShipChange);
     1986    cmShowGreatLibTech: Result := SizeOf(Integer);
     1987    cmShowCityChanged: Result := SizeOf(Integer);
     1988    cmShowPeaceViolation: Result := SizeOf(Integer);
     1989    cmShowMoving: Result := SizeOf(TShowMove);
     1990    cmShowUnitChanged: Result := SizeOf(Integer);
     1991    cmShowMissionResult: Result := SizeOf(Cardinal);
     1992    cmShowAfterMove: Result := SizeOf(Integer);
     1993    cmShowAfterAttack: Result := SizeOf(Integer);
     1994    cmShowSupportAllianceAgainst: Result := SizeOf(Integer);
     1995    cmShowCancelTreatyByAlliance: Result := SizeOf(Integer);
     1996    cmShowEndContact: Result := 0;
     1997    cmShowGame: Result := 0;
     1998    //sIntCancelTreaty: Result := SizeOf(Integer);
     1999    else begin
     2000      Result := 0;
     2001    end;
     2002  end;
     2003end;
     2004
     2005
    19212006initialization
    19222007
Note: See TracChangeset for help on using the changeset viewer.