Ignore:
Timestamp:
Mar 9, 2021, 9:19:49 AM (3 years ago)
Author:
chronos
Message:
  • Modified: Synced code with current trunk version.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/highdpi/AI/StdAI/StdAI.lpr

    r210 r303  
    33
    44uses
    5   {$IFDEF DEBUG}Names in 'Names.pas',{$ENDIF}
     5 {$IFDEF DEBUG}Names in 'Names.pas', {$ENDIF}
    66  Protocol in 'Protocol.pas',
    77  CustomAI in 'CustomAI.pas',
     
    1111
    1212var
    13 AIList: array[0..nPl-1] of TCustomAI;
    14 Defender: integer;
     13  AIList: array[0..nPl - 1] of TCustomAI;
     14  Defender: integer;
    1515
    1616
    17 procedure Client(Command,Player:integer;var Data); stdcall;
    18 var
    19 p,y0,ToLoc: integer;
    20 UnitInfo: TUnitInfo;
    21 begin
    22 case Command of
    23   cInitModule:
    24     begin
    25     Server:=TInitModuleData(Data).Server;
    26     TInitModuleData(Data).DataSize:=RWDataSize;
     17  procedure Client(Command, Player: integer; var Data); stdcall;
     18  var
     19    p, y0, ToLoc: integer;
     20    UnitInfo: TUnitInfo;
     21  begin
     22    case Command of
     23      cInitModule:
     24      begin
     25        Server := TInitModuleData(Data).Server;
     26        TInitModuleData(Data).DataSize := RWDataSize;
     27      end;
     28      cNewGame, cLoadGame:
     29      begin
     30{$IFNDEF DEBUG}
     31        Randomize;
     32{$ENDIF}
     33        CustomAI.Init(TNewGameData(Data));
     34        for p := nPl - 1 downto 0 do
     35          if G.RO[p] <> nil then
     36          begin
     37            AIList[p] := TAI.Create(p);
     38            AIList[p].SetDataDefaults;
     39          end
     40          else
     41            AIList[p] := nil;
     42        Defender := -1;
     43      end;
     44      cGetReady:
     45        for p := nPl - 1 downto 0 do
     46          if AIList[p] <> nil then
     47            AIList[p].SetDataRandom;
     48      cBreakGame:
     49        for p := 0 to nPl - 1 do
     50          if AIList[p] <> nil then
     51            AIList[p].Free;
     52
     53      cTurn, cContinue, scContact..scDipBreak, cShowEndContact:
     54        AIList[Player].Process(Command, Data);
     55
     56      cShowAttacking, cShowCapturing:
     57        with TShowMove(Data) do
     58        begin
     59          y0 := FromLoc div G.lx;
     60          ToLoc := (FromLoc + (dx + y0 and 1 + G.lx + G.lx) shr 1) mod
     61            G.lx + G.lx * (y0 + dy);
     62          if G.RO[Player].Map[ToLoc] and fOwned <> 0 then
     63          begin
     64            UnitInfo.Loc := FromLoc;
     65            UnitInfo.mix := mix;
     66            UnitInfo.emix := emix;
     67            UnitInfo.Owner := Owner;
     68            UnitInfo.Health := Health;
     69            UnitInfo.Fuel := Fuel;
     70            UnitInfo.Job := jNone;
     71            UnitInfo.Exp := Exp;
     72            UnitInfo.Load := Load;
     73            UnitInfo.Flags := Flags;
     74            if Command = cShowAttacking then
     75              AIList[Player].OnBeforeEnemyAttack(UnitInfo, ToLoc, EndHealth,
     76                EndHealthDef)
     77            else
     78              AIList[Player].OnBeforeEnemyCapture(UnitInfo, ToLoc);
     79            Defender := Player;
     80          end;
     81        end;
     82      cShowAfterAttack:
     83        if Player = Defender then
     84        begin
     85          AIList[Player].OnAfterEnemyAttack;
     86          Defender := -1;
     87        end;
     88      cShowAfterMove:
     89        if Player = Defender then
     90        begin
     91          AIList[Player].OnAfterEnemyCapture;
     92          Defender := -1;
     93        end;
     94
     95      else {ignore other commands}
    2796    end;
    28   cNewGame,cLoadGame:
    29     begin
    30 {$IFNDEF DEBUG}Randomize;{$ENDIF}
    31     CustomAI.Init(TNewGameData(Data));
    32     for p:=nPl-1 downto 0 do
    33       if G.RO[p]<>nil then
    34         begin
    35         AIList[p]:=TAI.Create(p);
    36         AIList[p].SetDataDefaults;
    37         end
    38       else AIList[p]:=nil;
    39     Defender:=-1;
    40     end;
    41   cGetReady:
    42     for p:=nPl-1 downto 0 do
    43       if AIList[p]<>nil then AIList[p].SetDataRandom;
    44   cBreakGame:
    45     for p:=0 to nPl-1 do
    46       if AIList[p]<>nil then AIList[p].Free;
    47 
    48   cTurn, cContinue, scContact..scDipBreak, cShowEndContact:
    49     AIList[Player].Process(Command, Data);
    50 
    51   cShowAttacking, cShowCapturing:
    52     with TShowMove(Data) do
    53       begin
    54       y0:=FromLoc div G.lx;
    55       ToLoc:=(FromLoc+(dx+y0 and 1+G.lx+G.lx) shr 1) mod G.lx +G.lx*(y0+dy);
    56       if G.RO[Player].Map[ToLoc] and fOwned<>0 then
    57         begin
    58         UnitInfo.Loc:=FromLoc;
    59         UnitInfo.mix:=mix;
    60         UnitInfo.emix:=emix;
    61         UnitInfo.Owner:=Owner;
    62         UnitInfo.Health:=Health;
    63         UnitInfo.Fuel:=Fuel;
    64         UnitInfo.Job:=jNone;
    65         UnitInfo.Exp:=Exp;
    66         UnitInfo.Load:=Load;
    67         UnitInfo.Flags:=Flags;
    68         if Command=cShowAttacking then
    69           AIList[Player].OnBeforeEnemyAttack(UnitInfo, ToLoc, EndHealth,
    70             EndHealthDef)
    71         else AIList[Player].OnBeforeEnemyCapture(UnitInfo, ToLoc);
    72         Defender:=Player
    73         end
    74       end;
    75   cShowAfterAttack:
    76     if Player=Defender then
    77       begin
    78       AIList[Player].OnAfterEnemyAttack;
    79       Defender:=-1;
    80       end;
    81   cShowAfterMove:
    82     if Player=Defender then
    83       begin
    84       AIList[Player].OnAfterEnemyCapture;
    85       Defender:=-1;
    86       end;
    87 
    88   else {ignore other commands}
    89   end
    90 end;
     97  end;
    9198
    9299exports
    93 Client Name 'client';
     100  Client Name 'client';
    94101
    95102end.
    96 
    97 
    98 
Note: See TracChangeset for help on using the changeset viewer.