4
|
1 |
(*
|
|
2 |
* Hedgewars, a worms-like game
|
51
|
3 |
* Copyright (c) 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com>
|
4
|
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
|
48
|
40 |
uses uAIActions, uAIMisc, uMisc, uTeams, uConsts, uAIAmmoTests, uGears, SDLh, uConsole;
|
4
|
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
|
48
|
59 |
if isInMultiShoot or (CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].AttacksNum > 0)
|
|
60 |
then with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
|
4
|
61 |
a:= Ammo[CurSlot, CurAmmo].AmmoType
|
|
62 |
else a:= TAmmoType(random(ord(High(TAmmoType))));
|
|
63 |
aa:= a;
|
|
64 |
repeat
|
|
65 |
if Assigned(AmmoTests[a].Test)
|
|
66 |
and ((Flags = 0) or ((Flags and AmmoTests[a].Flags) <> 0)) then
|
|
67 |
if AmmoTests[a].Test(Me, Targets.ar[t], Flags, Time, Angle, Power) then
|
|
68 |
begin
|
|
69 |
AddAction(aia_Weapon, ord(a), 1000);
|
|
70 |
if Time <> 0 then AddAction(aia_Timer, Time div 1000, 400);
|
|
71 |
exit
|
|
72 |
end;
|
|
73 |
if a = High(TAmmoType) then a:= Low(TAmmoType)
|
|
74 |
else inc(a)
|
48
|
75 |
until isInMultiShoot or (a = aa) or (CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].AttacksNum > 0);
|
4
|
76 |
inc(t)
|
|
77 |
until (t >= Targets.Count)
|
|
78 |
end;
|
|
79 |
|
|
80 |
procedure TryGo(lvl, Flags: Longword);
|
|
81 |
var tmpGear: TGear;
|
|
82 |
i, t: integer;
|
|
83 |
begin
|
|
84 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
|
|
85 |
for t:= aia_Left to aia_Right do
|
|
86 |
if IsActionListEmpty then
|
|
87 |
begin
|
|
88 |
tmpGear:= Gear^;
|
|
89 |
i:= 0;
|
|
90 |
Gear.Message:= t;
|
|
91 |
while HHGo(Gear) do
|
|
92 |
begin
|
|
93 |
if (i mod 5 = 0) then
|
|
94 |
begin
|
|
95 |
FindTarget(Flags);
|
|
96 |
if not IsActionListEmpty then
|
|
97 |
begin
|
|
98 |
if i > 0 then
|
|
99 |
begin
|
|
100 |
AddAction(t, aim_push, 1000);
|
|
101 |
AddAction(aia_WaitX, round(Gear.X), 0);
|
|
102 |
AddAction(t, aim_release, 0)
|
|
103 |
end;
|
|
104 |
Gear^:= tmpGear;
|
|
105 |
exit
|
|
106 |
end
|
|
107 |
end;
|
|
108 |
inc(i)
|
|
109 |
end;
|
|
110 |
Gear^:= tmpGear
|
|
111 |
end
|
|
112 |
end;
|
|
113 |
|
|
114 |
begin
|
|
115 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
|
48
|
116 |
if ((Gear.State and (gstAttacked or gstAttacking or gstMoving or gstFalling)) <> 0)
|
|
117 |
or isInMultiShoot then exit;
|
4
|
118 |
|
|
119 |
FillTargets(Targets);
|
|
120 |
|
|
121 |
TryGo(0, 0);
|
|
122 |
|
|
123 |
if IsActionListEmpty then
|
|
124 |
TryGo(0, ctfNotFull);
|
|
125 |
if IsActionListEmpty then
|
|
126 |
TryGo(0, ctfBreach);
|
|
127 |
|
|
128 |
if IsActionListEmpty then
|
|
129 |
begin
|
48
|
130 |
if CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].AttacksNum = 0 then
|
|
131 |
begin
|
|
132 |
AddAction(aia_Weapon, ord(amSkip), 1000);
|
|
133 |
AddAction(aia_Attack, aim_push, 1000);
|
|
134 |
end else ParseCommand('skip');
|
4
|
135 |
exit
|
|
136 |
end;
|
|
137 |
|
|
138 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
|
|
139 |
begin
|
|
140 |
if (Angle > 0) then AddAction(aia_LookRight, 0, 200)
|
|
141 |
else if (Angle < 0) then AddAction(aia_LookLeft, 0, 200);
|
|
142 |
Angle:= integer(Gear.Angle) - Abs(Angle);
|
|
143 |
if Angle > 0 then
|
|
144 |
begin
|
|
145 |
AddAction(aia_Up, aim_push, 500);
|
|
146 |
AddAction(aia_Up, aim_release, Angle)
|
|
147 |
end else if Angle < 0 then
|
|
148 |
begin
|
|
149 |
AddAction(aia_Down, aim_push, 500);
|
|
150 |
AddAction(aia_Down, aim_release, -Angle)
|
|
151 |
end;
|
|
152 |
AddAction(aia_attack, aim_push, 300);
|
|
153 |
AddAction(aia_attack, aim_release, Power);
|
|
154 |
end
|
|
155 |
end;
|
|
156 |
|
|
157 |
procedure ProcessBot;
|
|
158 |
begin
|
|
159 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
|
|
160 |
if (Gear <> nil)and((Gear.State and gstHHDriven) <> 0) then
|
|
161 |
begin
|
|
162 |
if IsActionListEmpty then Think;
|
|
163 |
ProcessAction
|
|
164 |
end
|
|
165 |
end;
|
|
166 |
|
|
167 |
end.
|