source: branches/delphi/AI/AIProject.dpr

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