4
|
1 |
unit uAIMisc;
|
|
2 |
interface
|
64
|
3 |
uses SDLh, uConsts;
|
4
|
4 |
|
64
|
5 |
type TTarget = record
|
|
6 |
Point: TPoint;
|
|
7 |
Score: integer;
|
|
8 |
end;
|
|
9 |
TTargets = record
|
|
10 |
Count: Longword;
|
|
11 |
ar: array[0..cMaxHHIndex*5] of TTarget;
|
4
|
12 |
end;
|
64
|
13 |
|
4
|
14 |
procedure FillTargets(var Targets: TTargets);
|
64
|
15 |
function DxDy2AttackAngle(const _dY, _dX: Extended): integer;
|
4
|
16 |
function TestColl(x, y, r: integer): boolean;
|
|
17 |
function NoMyHHNear(x, y, r: integer): boolean;
|
|
18 |
|
|
19 |
implementation
|
64
|
20 |
uses uTeams, uMisc, uLand;
|
4
|
21 |
|
|
22 |
procedure FillTargets(var Targets: TTargets);
|
|
23 |
var t: PTeam;
|
64
|
24 |
i: Longword;
|
4
|
25 |
begin
|
|
26 |
Targets.Count:= 0;
|
|
27 |
t:= TeamsList;
|
|
28 |
while t <> nil do
|
|
29 |
begin
|
|
30 |
if t <> CurrentTeam then
|
|
31 |
for i:= 0 to cMaxHHIndex do
|
|
32 |
if t.Hedgehogs[i].Gear <> nil then
|
|
33 |
begin
|
|
34 |
with Targets.ar[Targets.Count], t.Hedgehogs[i] do
|
|
35 |
begin
|
64
|
36 |
Point.X:= Round(Gear.X);
|
|
37 |
Point.Y:= Round(Gear.Y);
|
|
38 |
Score:= 100 - Gear.Health
|
4
|
39 |
end;
|
|
40 |
inc(Targets.Count)
|
|
41 |
end;
|
|
42 |
t:= t.Next
|
64
|
43 |
end
|
4
|
44 |
end;
|
|
45 |
|
64
|
46 |
function DxDy2AttackAngle(const _dY, _dX: Extended): integer;
|
4
|
47 |
const piDIVMaxAngle: Extended = pi/cMaxAngle;
|
|
48 |
asm
|
|
49 |
fld _dY
|
|
50 |
fld _dX
|
|
51 |
fpatan
|
|
52 |
fld piDIVMaxAngle
|
|
53 |
fdiv
|
|
54 |
sub esp, 4
|
|
55 |
fistp dword ptr [esp]
|
|
56 |
pop eax
|
|
57 |
end;
|
|
58 |
|
|
59 |
function TestColl(x, y, r: integer): boolean;
|
|
60 |
begin
|
|
61 |
Result:=(((x-r) and $FFFFF800) = 0)and(((y-r) and $FFFFFC00) = 0) and (Land[y-r, x-r] <> 0);
|
|
62 |
if Result then exit;
|
|
63 |
Result:=(((x-r) and $FFFFF800) = 0)and(((y+r) and $FFFFFC00) = 0) and (Land[y+r, x-r] <> 0);
|
|
64 |
if Result then exit;
|
|
65 |
Result:=(((x+r) and $FFFFF800) = 0)and(((y-r) and $FFFFFC00) = 0) and (Land[y-r, x+r] <> 0);
|
|
66 |
if Result then exit;
|
|
67 |
Result:=(((x+r) and $FFFFF800) = 0)and(((y+r) and $FFFFFC00) = 0) and (Land[y+r, x+r] <> 0);
|
|
68 |
end;
|
|
69 |
|
|
70 |
function NoMyHHNear(x, y, r: integer): boolean;
|
|
71 |
var i: integer;
|
|
72 |
begin
|
|
73 |
i:= 0;
|
|
74 |
r:= sqr(r);
|
|
75 |
Result:= true;
|
|
76 |
repeat
|
|
77 |
with CurrentTeam.Hedgehogs[i] do
|
|
78 |
if Gear <> nil then
|
|
79 |
if sqr(Gear.X - x) + sqr(Gear.Y - y) <= r then
|
|
80 |
begin
|
|
81 |
Result:= false;
|
|
82 |
exit
|
|
83 |
end;
|
|
84 |
inc(i)
|
|
85 |
until i > cMaxHHIndex
|
|
86 |
end;
|
|
87 |
|
|
88 |
end.
|