4
|
1 |
(*
|
|
2 |
* Hedgewars, a worms-like game
|
|
3 |
* Copyright (c) 2005 Andrey Korotaev <unC0Rr@gmail.com>
|
|
4 |
*
|
|
5 |
* Distributed under the terms of the BSD-modified licence:
|
|
6 |
*
|
|
7 |
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8 |
* of this software and associated documentation files (the "Software"), to deal
|
|
9 |
* with the Software without restriction, including without limitation the
|
|
10 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
11 |
* sell copies of the Software, and to permit persons to whom the Software is
|
|
12 |
* furnished to do so, subject to the following conditions:
|
|
13 |
*
|
|
14 |
* 1. Redistributions of source code must retain the above copyright notice,
|
|
15 |
* this list of conditions and the following disclaimer.
|
|
16 |
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
17 |
* this list of conditions and the following disclaimer in the documentation
|
|
18 |
* and/or other materials provided with the distribution.
|
|
19 |
* 3. The name of the author may not be used to endorse or promote products
|
|
20 |
* derived from this software without specific prior written permission.
|
|
21 |
*
|
|
22 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
23 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
24 |
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
|
25 |
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
26 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
27 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
28 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
29 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
30 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
31 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
32 |
*)
|
|
33 |
|
|
34 |
unit uAI;
|
|
35 |
interface
|
|
36 |
{$INCLUDE options.inc}
|
|
37 |
procedure ProcessBot;
|
|
38 |
|
|
39 |
implementation
|
|
40 |
uses uAIActions, uAIMisc, uMisc, uTeams, uConsts, uAIAmmoTests, uGears, SDLh;
|
|
41 |
|
|
42 |
procedure Think;
|
|
43 |
var Targets: TTargets;
|
|
44 |
Angle, Power: integer;
|
|
45 |
Time: Longword;
|
|
46 |
|
|
47 |
procedure FindTarget(Flags: Longword);
|
|
48 |
var t: integer;
|
|
49 |
a, aa: TAmmoType;
|
|
50 |
Me: TPoint;
|
|
51 |
begin
|
|
52 |
t:= 0;
|
|
53 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
|
|
54 |
begin
|
|
55 |
Me.X:= round(Gear.X);
|
|
56 |
Me.Y:= round(Gear.Y);
|
|
57 |
end;
|
|
58 |
repeat
|
|
59 |
if isInMultiShoot then with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
|
|
60 |
a:= Ammo[CurSlot, CurAmmo].AmmoType
|
|
61 |
else a:= TAmmoType(random(ord(High(TAmmoType))));
|
|
62 |
aa:= a;
|
|
63 |
repeat
|
|
64 |
if Assigned(AmmoTests[a].Test)
|
|
65 |
and ((Flags = 0) or ((Flags and AmmoTests[a].Flags) <> 0)) then
|
|
66 |
if AmmoTests[a].Test(Me, Targets.ar[t], Flags, Time, Angle, Power) then
|
|
67 |
begin
|
|
68 |
AddAction(aia_Weapon, ord(a), 1000);
|
|
69 |
if Time <> 0 then AddAction(aia_Timer, Time div 1000, 400);
|
|
70 |
exit
|
|
71 |
end;
|
|
72 |
if a = High(TAmmoType) then a:= Low(TAmmoType)
|
|
73 |
else inc(a)
|
|
74 |
until isInMultiShoot or (a = aa);
|
|
75 |
inc(t)
|
|
76 |
until (t >= Targets.Count)
|
|
77 |
end;
|
|
78 |
|
|
79 |
procedure TryGo(lvl, Flags: Longword);
|
|
80 |
var tmpGear: TGear;
|
|
81 |
i, t: integer;
|
|
82 |
begin
|
|
83 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
|
|
84 |
for t:= aia_Left to aia_Right do
|
|
85 |
if IsActionListEmpty then
|
|
86 |
begin
|
|
87 |
tmpGear:= Gear^;
|
|
88 |
i:= 0;
|
|
89 |
Gear.Message:= t;
|
|
90 |
while HHGo(Gear) do
|
|
91 |
begin
|
|
92 |
if (i mod 5 = 0) then
|
|
93 |
begin
|
|
94 |
FindTarget(Flags);
|
|
95 |
if not IsActionListEmpty then
|
|
96 |
begin
|
|
97 |
if i > 0 then
|
|
98 |
begin
|
|
99 |
AddAction(t, aim_push, 1000);
|
|
100 |
AddAction(aia_WaitX, round(Gear.X), 0);
|
|
101 |
AddAction(t, aim_release, 0)
|
|
102 |
end;
|
|
103 |
Gear^:= tmpGear;
|
|
104 |
exit
|
|
105 |
end
|
|
106 |
end;
|
|
107 |
inc(i)
|
|
108 |
end;
|
|
109 |
Gear^:= tmpGear
|
|
110 |
end
|
|
111 |
end;
|
|
112 |
|
|
113 |
begin
|
|
114 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
|
|
115 |
if ((Gear.State and (gstAttacked or gstAttacking or gstMoving or gstFalling)) <> 0) then exit;
|
|
116 |
|
|
117 |
FillTargets(Targets);
|
|
118 |
|
|
119 |
TryGo(0, 0);
|
|
120 |
|
|
121 |
if IsActionListEmpty then
|
|
122 |
TryGo(0, ctfNotFull);
|
|
123 |
if IsActionListEmpty then
|
|
124 |
TryGo(0, ctfBreach);
|
|
125 |
|
|
126 |
if IsActionListEmpty then
|
|
127 |
begin
|
|
128 |
AddAction(aia_Weapon, ord(amSkip), 1000);
|
|
129 |
AddAction(aia_Attack, aim_push, 1000);
|
|
130 |
exit
|
|
131 |
end;
|
|
132 |
|
|
133 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
|
|
134 |
begin
|
|
135 |
if (Angle > 0) then AddAction(aia_LookRight, 0, 200)
|
|
136 |
else if (Angle < 0) then AddAction(aia_LookLeft, 0, 200);
|
|
137 |
Angle:= integer(Gear.Angle) - Abs(Angle);
|
|
138 |
if Angle > 0 then
|
|
139 |
begin
|
|
140 |
AddAction(aia_Up, aim_push, 500);
|
|
141 |
AddAction(aia_Up, aim_release, Angle)
|
|
142 |
end else if Angle < 0 then
|
|
143 |
begin
|
|
144 |
AddAction(aia_Down, aim_push, 500);
|
|
145 |
AddAction(aia_Down, aim_release, -Angle)
|
|
146 |
end;
|
|
147 |
AddAction(aia_attack, aim_push, 300);
|
|
148 |
AddAction(aia_attack, aim_release, Power);
|
|
149 |
end
|
|
150 |
end;
|
|
151 |
|
|
152 |
procedure ProcessBot;
|
|
153 |
begin
|
|
154 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
|
|
155 |
if (Gear <> nil)and((Gear.State and gstHHDriven) <> 0) then
|
|
156 |
begin
|
|
157 |
if IsActionListEmpty then Think;
|
|
158 |
ProcessAction
|
|
159 |
end
|
|
160 |
end;
|
|
161 |
|
|
162 |
end.
|