1 | {$INCLUDE Switches.inc}
|
---|
2 | library StdAI;
|
---|
3 |
|
---|
4 | uses
|
---|
5 | {$IFDEF DEBUG}Names in 'Names.pas', {$ENDIF}
|
---|
6 | Protocol in 'Protocol.pas',
|
---|
7 | CustomAI in 'CustomAI.pas',
|
---|
8 | ToolAI in 'ToolAI.pas',
|
---|
9 | AI in 'AI.pas',
|
---|
10 | Barbarina in 'Barbarina.pas';
|
---|
11 |
|
---|
12 | var
|
---|
13 | AIList: array[0..nPl - 1] of TCustomAI;
|
---|
14 | Defender: Integer;
|
---|
15 |
|
---|
16 |
|
---|
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}
|
---|
96 | end;
|
---|
97 | end;
|
---|
98 |
|
---|
99 | exports
|
---|
100 | Client Name 'client';
|
---|
101 |
|
---|
102 | end.
|
---|