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