source: branches/AlphaChannel/AI/StdAI/StdAI.lpr

Last change on this file was 160, checked in by chronos, 6 years ago
  • Added: StdAI from original game. Previously used only AI dev kit.
File size: 2.3 KB
Line 
1{$INCLUDE Switches.inc}
2library StdAI;
3
4uses
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
12var
13AIList: array[0..nPl-1] of TCustomAI;
14Defender: integer;
15
16
17procedure Client(Command,Player:integer;var Data); stdcall;
18var
19p,y0,ToLoc: integer;
20UnitInfo: TUnitInfo;
21begin
22case 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}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
90end;
91
92exports
93Client Name 'client';
94
95end.
96
97
98
Note: See TracBrowser for help on using the repository browser.