author | unc0rr |
Thu, 05 Oct 2006 16:33:18 +0000 | |
changeset 183 | 57c2ef19f719 |
parent 136 | 89970b70b076 |
child 191 | a03c2d037e24 |
permissions | -rw-r--r-- |
71 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
3 |
* Copyright (c) 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
183 | 5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
71 | 8 |
* |
183 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
71 | 13 |
* |
183 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
71 | 17 |
*) |
18 |
||
4 | 19 |
unit uAIMisc; |
20 |
interface |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
21 |
uses SDLh, uConsts, uGears; |
80 | 22 |
{$INCLUDE options.inc} |
4 | 23 |
|
64 | 24 |
type TTarget = record |
25 |
Point: TPoint; |
|
26 |
Score: integer; |
|
27 |
end; |
|
28 |
TTargets = record |
|
29 |
Count: Longword; |
|
30 |
ar: array[0..cMaxHHIndex*5] of TTarget; |
|
4 | 31 |
end; |
80 | 32 |
TJumpType = (jmpNone, jmpHJump, jmpLJump); |
75 | 33 |
TGoInfo = record |
34 |
Ticks: Longword; |
|
80 | 35 |
FallPix: Longword; |
36 |
JumpType: TJumpType; |
|
75 | 37 |
end; |
64 | 38 |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
39 |
procedure FillTargets; |
70 | 40 |
procedure FillBonuses(isAfterAttack: boolean); |
71 | 41 |
procedure AwareOfExplosion(x, y, r: integer); |
70 | 42 |
function RatePlace(Gear: PGear): integer; |
4 | 43 |
function TestColl(x, y, r: integer): boolean; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
44 |
function RateExplosion(Me: PGear; x, y, r: integer): integer; |
79 | 45 |
function RateShove(Me: PGear; x, y, r, power: integer): integer; |
80 | 46 |
function HHGo(Gear, AltGear: PGear; out GoInfo: TGoInfo): boolean; |
136 | 47 |
function rndSign(num: integer): integer; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
48 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
49 |
var ThinkingHH: PGear; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
50 |
Targets: TTargets; |
4 | 51 |
|
52 |
implementation |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
53 |
uses uTeams, uMisc, uLand, uCollisions; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
54 |
const KillScore = 200; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
55 |
MAXBONUS = 1024; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
56 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
57 |
type TBonus = record |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
58 |
X, Y: integer; |
70 | 59 |
Radius: integer; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
60 |
Score: integer; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
61 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
62 |
var bonuses: record |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
63 |
Count: Longword; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
64 |
ar: array[0..Pred(MAXBONUS)] of TBonus; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
65 |
end; |
71 | 66 |
KnownExplosion: record |
67 |
X, Y, Radius: integer |
|
68 |
end = (X: 0; Y: 0; Radius: 0); |
|
4 | 69 |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
70 |
procedure FillTargets; |
4 | 71 |
var t: PTeam; |
64 | 72 |
i: Longword; |
4 | 73 |
begin |
74 |
Targets.Count:= 0; |
|
75 |
t:= TeamsList; |
|
76 |
while t <> nil do |
|
77 |
begin |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
78 |
for i:= 0 to cMaxHHIndex do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
79 |
if (t.Hedgehogs[i].Gear <> nil) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
80 |
and (t.Hedgehogs[i].Gear <> ThinkingHH) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
81 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
82 |
with Targets.ar[Targets.Count], t.Hedgehogs[i] do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
83 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
84 |
Point.X:= Round(Gear.X); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
85 |
Point.Y:= Round(Gear.Y); |
74 | 86 |
if t.Color <> CurrentTeam.Color then Score:= Gear.Health |
87 |
else Score:= -Gear.Health |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
88 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
89 |
inc(Targets.Count) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
90 |
end; |
4 | 91 |
t:= t.Next |
64 | 92 |
end |
4 | 93 |
end; |
94 |
||
70 | 95 |
procedure FillBonuses(isAfterAttack: boolean); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
96 |
var Gear: PGear; |
70 | 97 |
MyColor: Longword; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
98 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
99 |
procedure AddBonus(x, y: integer; r: Longword; s: integer); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
100 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
101 |
bonuses.ar[bonuses.Count].x:= x; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
102 |
bonuses.ar[bonuses.Count].y:= y; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
103 |
bonuses.ar[bonuses.Count].Radius:= r; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
104 |
bonuses.ar[bonuses.Count].Score:= s; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
105 |
inc(bonuses.Count); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
106 |
TryDo(bonuses.Count <= MAXBONUS, 'Bonuses overflow', true) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
107 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
108 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
109 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
110 |
bonuses.Count:= 0; |
70 | 111 |
MyColor:= PHedgehog(ThinkingHH.Hedgehog).Team.Color; |
95 | 112 |
SDL_LockMutex(GearsListMutex); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
113 |
Gear:= GearsList; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
114 |
while Gear <> nil do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
115 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
116 |
case Gear.Kind of |
70 | 117 |
gtCase: AddBonus(round(Gear.X), round(Gear.Y), 33, 25); |
74 | 118 |
gtMine: if (Gear.State and gstAttacking) = 0 then AddBonus(round(Gear.X), round(Gear.Y), 50, -50) |
119 |
else AddBonus(round(Gear.X), round(Gear.Y), 100, -50); // mine is on |
|
70 | 120 |
gtDynamite: AddBonus(round(Gear.X), round(Gear.Y), 150, -75); |
121 |
gtHedgehog: begin |
|
74 | 122 |
if Gear.Damage >= Gear.Health then AddBonus(round(Gear.X), round(Gear.Y), 60, -25) else |
123 |
if isAfterAttack and (ThinkingHH.Hedgehog <> Gear.Hedgehog) then |
|
124 |
if (MyColor = PHedgehog(Gear.Hedgehog).Team.Color) then AddBonus(round(Gear.X), round(Gear.Y), 150, -3) // hedgehog-friend |
|
125 |
else AddBonus(round(Gear.X), round(Gear.Y), 100, 3) |
|
70 | 126 |
end; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
127 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
128 |
Gear:= Gear.NextGear |
71 | 129 |
end; |
95 | 130 |
SDL_UnlockMutex(GearsListMutex); |
71 | 131 |
if isAfterAttack and (KnownExplosion.Radius > 0) then |
132 |
with KnownExplosion do |
|
74 | 133 |
AddBonus(X, Y, Radius + 10, -Radius); |
71 | 134 |
end; |
135 |
||
136 |
procedure AwareOfExplosion(x, y, r: integer); |
|
137 |
begin |
|
138 |
KnownExplosion.X:= x; |
|
139 |
KnownExplosion.Y:= y; |
|
140 |
KnownExplosion.Radius:= r |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
141 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
142 |
|
70 | 143 |
function RatePlace(Gear: PGear): integer; |
144 |
var i, r: integer; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
145 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
146 |
Result:= 0; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
147 |
for i:= 0 to Pred(bonuses.Count) do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
148 |
with bonuses.ar[i] do |
70 | 149 |
begin |
150 |
r:= round(sqrt(sqr(Gear.X - X) + sqr(Gear.Y - y))); |
|
151 |
if r < Radius then |
|
152 |
inc(Result, Score * (Radius - r)) |
|
153 |
end; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
154 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
155 |
|
4 | 156 |
function TestColl(x, y, r: integer): boolean; |
157 |
begin |
|
158 |
Result:=(((x-r) and $FFFFF800) = 0)and(((y-r) and $FFFFFC00) = 0) and (Land[y-r, x-r] <> 0); |
|
159 |
if Result then exit; |
|
160 |
Result:=(((x-r) and $FFFFF800) = 0)and(((y+r) and $FFFFFC00) = 0) and (Land[y+r, x-r] <> 0); |
|
161 |
if Result then exit; |
|
162 |
Result:=(((x+r) and $FFFFF800) = 0)and(((y-r) and $FFFFFC00) = 0) and (Land[y-r, x+r] <> 0); |
|
163 |
if Result then exit; |
|
164 |
Result:=(((x+r) and $FFFFF800) = 0)and(((y+r) and $FFFFFC00) = 0) and (Land[y+r, x+r] <> 0); |
|
165 |
end; |
|
166 |
||
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
167 |
function RateExplosion(Me: PGear; x, y, r: integer): integer; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
168 |
var i, dmg: integer; |
4 | 169 |
begin |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
170 |
Result:= 0; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
171 |
// add our virtual position |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
172 |
with Targets.ar[Targets.Count] do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
173 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
174 |
Point.x:= round(Me.X); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
175 |
Point.y:= round(Me.Y); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
176 |
Score:= - ThinkingHH.Health |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
177 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
178 |
// rate explosion |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
179 |
for i:= 0 to Targets.Count do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
180 |
with Targets.ar[i] do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
181 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
182 |
dmg:= r - Round(sqrt(sqr(Point.x - x) + sqr(Point.y - y))); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
183 |
if dmg > 0 then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
184 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
185 |
dmg:= dmg shr 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
186 |
if dmg > abs(Score) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
187 |
if Score > 0 then inc(Result, KillScore) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
188 |
else dec(Result, KillScore * 3) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
189 |
else |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
190 |
if Score > 0 then inc(Result, dmg) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
191 |
else dec(Result, dmg * 3) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
192 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
193 |
end; |
70 | 194 |
Result:= Result * 1024 |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
195 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
196 |
|
79 | 197 |
function RateShove(Me: PGear; x, y, r, power: integer): integer; |
198 |
var i, dmg: integer; |
|
199 |
begin |
|
200 |
Result:= 0; |
|
201 |
for i:= 0 to Targets.Count do |
|
202 |
with Targets.ar[i] do |
|
203 |
begin |
|
204 |
dmg:= r - Round(sqrt(sqr(Point.x - x) + sqr(Point.y - y))); |
|
205 |
if dmg > 0 then |
|
206 |
begin |
|
207 |
if power > abs(Score) then |
|
208 |
if Score > 0 then inc(Result, KillScore) |
|
209 |
else dec(Result, KillScore * 3) |
|
210 |
else |
|
211 |
if Score > 0 then inc(Result, power) |
|
212 |
else dec(Result, power * 3) |
|
213 |
end; |
|
214 |
end; |
|
215 |
Result:= Result * 1024 |
|
216 |
end; |
|
217 |
||
80 | 218 |
function HHJump(Gear: PGear; JumpType: TJumpType; out GoInfo: TGoInfo): boolean; |
219 |
var bX, bY: integer; |
|
220 |
begin |
|
221 |
Result:= false; |
|
222 |
GoInfo.Ticks:= 0; |
|
223 |
GoInfo.FallPix:= 0; |
|
224 |
GoInfo.JumpType:= jmpNone; |
|
225 |
bX:= round(Gear.X); |
|
226 |
bY:= round(Gear.Y); |
|
227 |
case JumpType of |
|
228 |
jmpNone: exit; |
|
229 |
jmpHJump: if not TestCollisionYwithGear(Gear, -1) then |
|
230 |
begin |
|
231 |
Gear.dY:= -0.20; |
|
108 | 232 |
Gear.dX:= 0.0000001 * hwSign(Gear.dX); |
233 |
Gear.X:= Gear.X - hwSign(Gear.dX)*0.00008; // shift compensation |
|
80 | 234 |
Gear.State:= Gear.State or gstFalling or gstHHJumping; |
235 |
end else exit; |
|
236 |
jmpLJump: begin |
|
237 |
if not TestCollisionYwithGear(Gear, -1) then |
|
108 | 238 |
if not TestCollisionXwithXYShift(Gear, 0, -2, hwSign(Gear.dX)) then Gear.Y:= Gear.Y - 2 else |
239 |
if not TestCollisionXwithXYShift(Gear, 0, -1, hwSign(Gear.dX)) then Gear.Y:= Gear.Y - 1; |
|
240 |
if not (TestCollisionXwithGear(Gear, hwSign(Gear.dX)) |
|
80 | 241 |
or TestCollisionYwithGear(Gear, -1)) then |
242 |
begin |
|
243 |
Gear.dY:= -0.15; |
|
108 | 244 |
Gear.dX:= hwSign(Gear.dX) * 0.15; |
80 | 245 |
Gear.State:= Gear.State or gstFalling or gstHHJumping |
82 | 246 |
end else exit |
80 | 247 |
end |
248 |
end; |
|
249 |
||
250 |
repeat |
|
251 |
if Gear.Y + cHHRadius >= cWaterLine then exit; |
|
252 |
if (Gear.State and gstFalling) <> 0 then |
|
253 |
begin |
|
254 |
if (GoInfo.Ticks = 350) then |
|
255 |
if (abs(Gear.dX) < 0.0000002) and (Gear.dY < -0.02) then |
|
256 |
begin |
|
257 |
Gear.dY:= -0.25; |
|
108 | 258 |
Gear.dX:= hwSign(Gear.dX) * 0.02 |
80 | 259 |
end; |
108 | 260 |
if TestCollisionXwithGear(Gear, hwSign(Gear.dX)) then Gear.dX:= 0.0000001 * hwSign(Gear.dX); |
80 | 261 |
Gear.X:= Gear.X + Gear.dX; |
262 |
inc(GoInfo.Ticks); |
|
263 |
Gear.dY:= Gear.dY + cGravity; |
|
264 |
if Gear.dY > 0.40 then exit; |
|
265 |
if (Gear.dY < 0)and TestCollisionYwithGear(Gear, -1) then Gear.dY:= 0; |
|
266 |
Gear.Y:= Gear.Y + Gear.dY; |
|
267 |
if (Gear.dY >= 0)and TestCollisionYwithGear(Gear, 1) then |
|
268 |
begin |
|
269 |
Gear.State:= Gear.State and not (gstFalling or gstHHJumping); |
|
270 |
Gear.dY:= 0; |
|
271 |
case JumpType of |
|
272 |
jmpHJump: if (bY - Gear.Y > 5) then |
|
273 |
begin |
|
274 |
Result:= true; |
|
275 |
GoInfo.JumpType:= jmpHJump; |
|
276 |
inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after |
|
277 |
end; |
|
278 |
jmpLJump: if abs(bX - Gear.X) > 30 then |
|
279 |
begin |
|
280 |
Result:= true; |
|
281 |
GoInfo.JumpType:= jmpLJump; |
|
282 |
inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after |
|
283 |
end; |
|
284 |
end; |
|
285 |
exit |
|
286 |
end; |
|
287 |
end; |
|
288 |
until false; |
|
289 |
end; |
|
290 |
||
291 |
function HHGo(Gear, AltGear: PGear; out GoInfo: TGoInfo): boolean; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
292 |
var pX, pY: integer; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
293 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
294 |
Result:= false; |
80 | 295 |
AltGear^:= Gear^; |
296 |
||
75 | 297 |
GoInfo.Ticks:= 0; |
80 | 298 |
GoInfo.FallPix:= 0; |
299 |
GoInfo.JumpType:= jmpNone; |
|
4 | 300 |
repeat |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
301 |
pX:= round(Gear.X); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
302 |
pY:= round(Gear.Y); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
303 |
if pY + cHHRadius >= cWaterLine then exit; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
304 |
if (Gear.State and gstFalling) <> 0 then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
305 |
begin |
75 | 306 |
inc(GoInfo.Ticks); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
307 |
Gear.dY:= Gear.dY + cGravity; |
75 | 308 |
if Gear.dY > 0.40 then |
309 |
begin |
|
80 | 310 |
Goinfo.FallPix:= 0; |
82 | 311 |
HHJump(AltGear, jmpLJump, GoInfo); // try ljump enstead of fall with damage |
75 | 312 |
exit |
313 |
end; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
314 |
Gear.Y:= Gear.Y + Gear.dY; |
80 | 315 |
if round(Gear.Y) > pY then inc(GoInfo.FallPix); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
316 |
if TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
317 |
begin |
75 | 318 |
inc(GoInfo.Ticks, 300); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
319 |
Gear.State:= Gear.State and not (gstFalling or gstHHJumping); |
75 | 320 |
Gear.dY:= 0; |
321 |
Result:= true; |
|
82 | 322 |
HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall |
75 | 323 |
exit |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
324 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
325 |
continue |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
326 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
327 |
if (Gear.Message and gm_Left )<>0 then Gear.dX:= -1.0 else |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
328 |
if (Gear.Message and gm_Right )<>0 then Gear.dX:= 1.0 else exit; |
108 | 329 |
if TestCollisionXwithGear(Gear, hwSign(Gear.dX)) then |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
330 |
begin |
108 | 331 |
if not (TestCollisionXwithXYShift(Gear, 0, -6, hwSign(Gear.dX)) |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
332 |
or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1; |
108 | 333 |
if not (TestCollisionXwithXYShift(Gear, 0, -5, hwSign(Gear.dX)) |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
334 |
or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1; |
108 | 335 |
if not (TestCollisionXwithXYShift(Gear, 0, -4, hwSign(Gear.dX)) |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
336 |
or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1; |
108 | 337 |
if not (TestCollisionXwithXYShift(Gear, 0, -3, hwSign(Gear.dX)) |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
338 |
or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1; |
108 | 339 |
if not (TestCollisionXwithXYShift(Gear, 0, -2, hwSign(Gear.dX)) |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
340 |
or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1; |
108 | 341 |
if not (TestCollisionXwithXYShift(Gear, 0, -1, hwSign(Gear.dX)) |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
342 |
or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
343 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
344 |
|
108 | 345 |
if not TestCollisionXwithGear(Gear, hwSign(Gear.dX)) then |
75 | 346 |
begin |
347 |
Gear.X:= Gear.X + Gear.dX; |
|
348 |
inc(GoInfo.Ticks, cHHStepTicks) |
|
349 |
end; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
350 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
351 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
352 |
Gear.Y:= Gear.Y + 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
353 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
354 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
355 |
Gear.Y:= Gear.Y + 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
356 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
357 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
358 |
Gear.Y:= Gear.Y + 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
359 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
360 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
361 |
Gear.Y:= Gear.Y + 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
362 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
363 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
364 |
Gear.Y:= Gear.Y + 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
365 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
366 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
367 |
Gear.Y:= Gear.Y + 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
368 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
369 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
370 |
Gear.Y:= Gear.Y - 6; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
371 |
Gear.dY:= 0; |
108 | 372 |
Gear.dX:= 0.0000001 * hwSign(Gear.dX); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
373 |
Gear.State:= Gear.State or gstFalling |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
374 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
375 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
376 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
377 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
378 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
379 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
380 |
end; |
75 | 381 |
if (pX <> round(Gear.X)) and ((Gear.State and gstFalling) = 0) then |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
382 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
383 |
Result:= true; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
384 |
exit |
75 | 385 |
end |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
386 |
until (pX = round(Gear.X)) and (pY = round(Gear.Y)) and ((Gear.State and gstFalling) = 0); |
80 | 387 |
HHJump(AltGear, jmpHJump, GoInfo) |
4 | 388 |
end; |
389 |
||
136 | 390 |
function rndSign(num: integer): integer; |
391 |
begin |
|
392 |
if random(2) = 0 then Result:= num |
|
393 |
else Result:= - num |
|
394 |
end; |
|
395 |
||
4 | 396 |
end. |