author | unc0rr |
Wed, 21 Feb 2007 19:18:05 +0000 | |
changeset 470 | 86ca84d5da74 |
parent 433 | 9f8f22094c0e |
child 498 | 9c8b385dc9a1 |
permissions | -rw-r--r-- |
71 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
393 | 3 |
* Copyright (c) 2005-2007 Andrey Korotaev <unC0Rr@gmail.com> |
71 | 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 |
|
351 | 21 |
uses SDLh, uConsts, uGears, uFloat; |
80 | 22 |
{$INCLUDE options.inc} |
369 | 23 |
|
64 | 24 |
type TTarget = record |
25 |
Point: TPoint; |
|
371 | 26 |
Score: LongInt; |
64 | 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); |
371 | 41 |
procedure AwareOfExplosion(x, y, r: LongInt); |
42 |
function RatePlace(Gear: PGear): LongInt; |
|
43 |
function TestColl(x, y, r: LongInt): boolean; |
|
44 |
function RateExplosion(Me: PGear; x, y, r: LongInt): LongInt; |
|
45 |
function RateShove(Me: PGear; x, y, r, power: LongInt): LongInt; |
|
369 | 46 |
function HHGo(Gear, AltGear: PGear; var GoInfo: TGoInfo): boolean; |
371 | 47 |
function AIrndSign(num: LongInt): LongInt; |
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; |
369 | 51 |
|
4 | 52 |
implementation |
369 | 53 |
uses uTeams, uMisc, uLand, uCollisions; |
66
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; |
369 | 56 |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
57 |
type TBonus = record |
371 | 58 |
X, Y: LongInt; |
59 |
Radius: LongInt; |
|
60 |
Score: LongInt; |
|
66
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 |
371 | 67 |
X, Y, Radius: LongInt |
71 | 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 |
369 | 79 |
if (t^.Hedgehogs[i].Gear <> nil) |
80 |
and (t^.Hedgehogs[i].Gear <> ThinkingHH) then |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
81 |
begin |
369 | 82 |
with Targets.ar[Targets.Count], t^.Hedgehogs[i] do |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
83 |
begin |
369 | 84 |
Point.X:= hwRound(Gear^.X); |
85 |
Point.Y:= hwRound(Gear^.Y); |
|
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; |
369 | 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 |
|
371 | 99 |
procedure AddBonus(x, y: LongInt; r: Longword; s: LongInt); |
66
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; |
369 | 111 |
MyColor:= PHedgehog(ThinkingHH^.Hedgehog)^.Team^.Color; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
112 |
Gear:= GearsList; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
113 |
while Gear <> nil do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
114 |
begin |
369 | 115 |
case Gear^.Kind of |
116 |
gtCase: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 33, 25); |
|
117 |
gtMine: if (Gear^.State and gstAttacking) = 0 then AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 50, -50) |
|
118 |
else AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, -50); // mine is on |
|
119 |
gtDynamite: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -75); |
|
70 | 120 |
gtHedgehog: begin |
369 | 121 |
if Gear^.Damage >= Gear^.Health then AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 60, -25) else |
122 |
if isAfterAttack and (ThinkingHH^.Hedgehog <> Gear^.Hedgehog) then |
|
123 |
if (MyColor = PHedgehog(Gear^.Hedgehog)^.Team^.Color) then AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -3) // hedgehog-friend |
|
124 |
else AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, 3) |
|
70 | 125 |
end; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
126 |
end; |
369 | 127 |
Gear:= Gear^.NextGear |
71 | 128 |
end; |
129 |
if isAfterAttack and (KnownExplosion.Radius > 0) then |
|
130 |
with KnownExplosion do |
|
74 | 131 |
AddBonus(X, Y, Radius + 10, -Radius); |
71 | 132 |
end; |
133 |
||
371 | 134 |
procedure AwareOfExplosion(x, y, r: LongInt); |
71 | 135 |
begin |
136 |
KnownExplosion.X:= x; |
|
137 |
KnownExplosion.Y:= y; |
|
138 |
KnownExplosion.Radius:= r |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
139 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
140 |
|
371 | 141 |
function RatePlace(Gear: PGear): LongInt; |
142 |
var i, r: LongInt; |
|
143 |
Result: LongInt; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
144 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
145 |
Result:= 0; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
146 |
for i:= 0 to Pred(bonuses.Count) do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
147 |
with bonuses.ar[i] do |
70 | 148 |
begin |
369 | 149 |
r:= hwRound(Distance(Gear^.X - X, Gear^.Y - y)); |
70 | 150 |
if r < Radius then |
151 |
inc(Result, Score * (Radius - r)) |
|
152 |
end; |
|
369 | 153 |
RatePlace:= Result |
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 |
|
371 | 156 |
function TestColl(x, y, r: LongInt): boolean; |
369 | 157 |
var b: boolean; |
4 | 158 |
begin |
369 | 159 |
b:= (((x-r) and $FFFFF800) = 0)and(((y-r) and $FFFFFC00) = 0) and (Land[y-r, x-r] <> 0); |
160 |
if b then exit(true); |
|
161 |
b:=(((x-r) and $FFFFF800) = 0)and(((y+r) and $FFFFFC00) = 0) and (Land[y+r, x-r] <> 0); |
|
162 |
if b then exit(true); |
|
163 |
b:=(((x+r) and $FFFFF800) = 0)and(((y-r) and $FFFFFC00) = 0) and (Land[y-r, x+r] <> 0); |
|
164 |
if b then exit(true); |
|
165 |
TestColl:=(((x+r) and $FFFFF800) = 0)and(((y+r) and $FFFFFC00) = 0) and (Land[y+r, x+r] <> 0) |
|
4 | 166 |
end; |
167 |
||
371 | 168 |
function RateExplosion(Me: PGear; x, y, r: LongInt): LongInt; |
169 |
var i, dmg, Result: LongInt; |
|
4 | 170 |
begin |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
171 |
Result:= 0; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
172 |
// add our virtual position |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
173 |
with Targets.ar[Targets.Count] do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
174 |
begin |
369 | 175 |
Point.x:= hwRound(Me^.X); |
176 |
Point.y:= hwRound(Me^.Y); |
|
177 |
Score:= - ThinkingHH^.Health |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
178 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
179 |
// rate explosion |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
180 |
for i:= 0 to Targets.Count do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
181 |
with Targets.ar[i] do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
182 |
begin |
369 | 183 |
dmg:= r - hwRound(Distance(Point.x - x, Point.y - y)); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
184 |
if dmg > 0 then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
185 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
186 |
dmg:= dmg shr 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
187 |
if dmg > abs(Score) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
188 |
if Score > 0 then inc(Result, KillScore) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
189 |
else dec(Result, KillScore * 3) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
190 |
else |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
191 |
if Score > 0 then inc(Result, dmg) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
192 |
else dec(Result, dmg * 3) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
193 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
194 |
end; |
369 | 195 |
RateExplosion:= Result * 1024 |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
196 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
197 |
|
371 | 198 |
function RateShove(Me: PGear; x, y, r, power: LongInt): LongInt; |
199 |
var i, dmg, Result: LongInt; |
|
79 | 200 |
begin |
201 |
Result:= 0; |
|
433 | 202 |
for i:= 0 to Pred(Targets.Count) do |
79 | 203 |
with Targets.ar[i] do |
204 |
begin |
|
369 | 205 |
dmg:= r - hwRound(Distance(Point.x - x, Point.y - y)); |
79 | 206 |
if dmg > 0 then |
207 |
begin |
|
208 |
if power > abs(Score) then |
|
209 |
if Score > 0 then inc(Result, KillScore) |
|
210 |
else dec(Result, KillScore * 3) |
|
211 |
else |
|
212 |
if Score > 0 then inc(Result, power) |
|
213 |
else dec(Result, power * 3) |
|
214 |
end; |
|
215 |
end; |
|
369 | 216 |
RateShove:= Result * 1024 |
79 | 217 |
end; |
218 |
||
369 | 219 |
function HHJump(Gear: PGear; JumpType: TJumpType; var GoInfo: TGoInfo): boolean; |
371 | 220 |
var bX, bY: LongInt; |
369 | 221 |
Result: boolean; |
80 | 222 |
begin |
223 |
Result:= false; |
|
224 |
GoInfo.Ticks:= 0; |
|
225 |
GoInfo.FallPix:= 0; |
|
226 |
GoInfo.JumpType:= jmpNone; |
|
369 | 227 |
bX:= hwRound(Gear^.X); |
228 |
bY:= hwRound(Gear^.Y); |
|
80 | 229 |
case JumpType of |
369 | 230 |
jmpNone: exit(Result); |
80 | 231 |
jmpHJump: if not TestCollisionYwithGear(Gear, -1) then |
232 |
begin |
|
369 | 233 |
Gear^.dY:= -_0_2; |
234 |
SetLittle(Gear^.dX); |
|
235 |
Gear^.State:= Gear^.State or gstFalling or gstHHJumping; |
|
236 |
end else exit(Result); |
|
80 | 237 |
jmpLJump: begin |
238 |
if not TestCollisionYwithGear(Gear, -1) then |
|
369 | 239 |
if not TestCollisionXwithXYShift(Gear, 0, -2, hwSign(Gear^.dX)) then Gear^.Y:= Gear^.Y - 2 else |
240 |
if not TestCollisionXwithXYShift(Gear, 0, -1, hwSign(Gear^.dX)) then Gear^.Y:= Gear^.Y - 1; |
|
241 |
if not (TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) |
|
80 | 242 |
or TestCollisionYwithGear(Gear, -1)) then |
243 |
begin |
|
433 | 244 |
Gear^.dY:= -_0_15; |
369 | 245 |
Gear^.dX:= hwSign(Gear^.dX) * _0_15; |
246 |
Gear^.State:= Gear^.State or gstFalling or gstHHJumping |
|
247 |
end else exit(Result) |
|
80 | 248 |
end |
249 |
end; |
|
250 |
||
251 |
repeat |
|
369 | 252 |
if not (Gear^.Y + cHHRadius < cWaterLine) then exit(Result); |
253 |
if (Gear^.State and gstFalling) <> 0 then |
|
80 | 254 |
begin |
255 |
if (GoInfo.Ticks = 350) then |
|
433 | 256 |
if (not (hwAbs(Gear^.dX) > cLittle)) and (Gear^.dY < -_0_02) then |
80 | 257 |
begin |
369 | 258 |
Gear^.dY:= -_0_25; |
259 |
Gear^.dX:= hwSign(Gear^.dX) * _0_02 |
|
80 | 260 |
end; |
369 | 261 |
if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then SetLittle(Gear^.dX); |
262 |
Gear^.X:= Gear^.X + Gear^.dX; |
|
80 | 263 |
inc(GoInfo.Ticks); |
369 | 264 |
Gear^.dY:= Gear^.dY + cGravity; |
265 |
if Gear^.dY > _0_4 then exit(Result); |
|
266 |
if (Gear^.dY.isNegative)and TestCollisionYwithGear(Gear, -1) then Gear^.dY:= 0; |
|
267 |
Gear^.Y:= Gear^.Y + Gear^.dY; |
|
268 |
if (not Gear^.dY.isNegative)and TestCollisionYwithGear(Gear, 1) then |
|
80 | 269 |
begin |
369 | 270 |
Gear^.State:= Gear^.State and not (gstFalling or gstHHJumping); |
271 |
Gear^.dY:= 0; |
|
80 | 272 |
case JumpType of |
369 | 273 |
jmpHJump: if (bY - Gear^.Y > 5) then |
80 | 274 |
begin |
275 |
Result:= true; |
|
276 |
GoInfo.JumpType:= jmpHJump; |
|
277 |
inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after |
|
278 |
end; |
|
369 | 279 |
jmpLJump: if hwAbs(bX - Gear^.X) > 30 then |
80 | 280 |
begin |
281 |
Result:= true; |
|
282 |
GoInfo.JumpType:= jmpLJump; |
|
283 |
inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after |
|
284 |
end; |
|
285 |
end; |
|
369 | 286 |
exit(Result) |
80 | 287 |
end; |
288 |
end; |
|
369 | 289 |
until false |
80 | 290 |
end; |
291 |
||
369 | 292 |
function HHGo(Gear, AltGear: PGear; var GoInfo: TGoInfo): boolean; |
371 | 293 |
var pX, pY: LongInt; |
369 | 294 |
Result: boolean; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
295 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
296 |
Result:= false; |
80 | 297 |
AltGear^:= Gear^; |
298 |
||
75 | 299 |
GoInfo.Ticks:= 0; |
80 | 300 |
GoInfo.FallPix:= 0; |
301 |
GoInfo.JumpType:= jmpNone; |
|
4 | 302 |
repeat |
369 | 303 |
pX:= hwRound(Gear^.X); |
304 |
pY:= hwRound(Gear^.Y); |
|
375 | 305 |
if pY + cHHRadius >= cWaterLine then exit(false); |
369 | 306 |
if (Gear^.State and gstFalling) <> 0 then |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
307 |
begin |
75 | 308 |
inc(GoInfo.Ticks); |
369 | 309 |
Gear^.dY:= Gear^.dY + cGravity; |
310 |
if Gear^.dY > _0_4 then |
|
75 | 311 |
begin |
80 | 312 |
Goinfo.FallPix:= 0; |
82 | 313 |
HHJump(AltGear, jmpLJump, GoInfo); // try ljump enstead of fall with damage |
369 | 314 |
exit(Result) |
75 | 315 |
end; |
369 | 316 |
Gear^.Y:= Gear^.Y + Gear^.dY; |
317 |
if hwRound(Gear^.Y) > pY then inc(GoInfo.FallPix); |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
318 |
if TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
319 |
begin |
75 | 320 |
inc(GoInfo.Ticks, 300); |
369 | 321 |
Gear^.State:= Gear^.State and not (gstFalling or gstHHJumping); |
322 |
Gear^.dY:= 0; |
|
75 | 323 |
Result:= true; |
82 | 324 |
HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall |
369 | 325 |
exit(Result) |
66
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 |
continue |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
328 |
end; |
369 | 329 |
if (Gear^.Message and gm_Left )<>0 then Gear^.dX:= -cLittle else |
330 |
if (Gear^.Message and gm_Right )<>0 then Gear^.dX:= cLittle else exit(Result); |
|
331 |
if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
332 |
begin |
369 | 333 |
if not (TestCollisionXwithXYShift(Gear, 0, -6, hwSign(Gear^.dX)) |
334 |
or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - 1; |
|
335 |
if not (TestCollisionXwithXYShift(Gear, 0, -5, hwSign(Gear^.dX)) |
|
336 |
or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - 1; |
|
337 |
if not (TestCollisionXwithXYShift(Gear, 0, -4, hwSign(Gear^.dX)) |
|
338 |
or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - 1; |
|
339 |
if not (TestCollisionXwithXYShift(Gear, 0, -3, hwSign(Gear^.dX)) |
|
340 |
or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - 1; |
|
341 |
if not (TestCollisionXwithXYShift(Gear, 0, -2, hwSign(Gear^.dX)) |
|
342 |
or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - 1; |
|
343 |
if not (TestCollisionXwithXYShift(Gear, 0, -1, hwSign(Gear^.dX)) |
|
344 |
or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - 1; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
345 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
346 |
|
369 | 347 |
if not TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then |
75 | 348 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
349 |
Gear^.X:= Gear^.X + hwSign(Gear^.dX); |
75 | 350 |
inc(GoInfo.Ticks, cHHStepTicks) |
351 |
end; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
352 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
353 |
begin |
369 | 354 |
Gear^.Y:= Gear^.Y + 1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
355 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
356 |
begin |
369 | 357 |
Gear^.Y:= Gear^.Y + 1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
358 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
359 |
begin |
369 | 360 |
Gear^.Y:= Gear^.Y + 1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
361 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
362 |
begin |
369 | 363 |
Gear^.Y:= Gear^.Y + 1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
364 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
365 |
begin |
369 | 366 |
Gear^.Y:= Gear^.Y + 1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
367 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
368 |
begin |
369 | 369 |
Gear^.Y:= Gear^.Y + 1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
370 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
371 |
begin |
369 | 372 |
Gear^.Y:= Gear^.Y - 6; |
373 |
Gear^.dY:= 0; |
|
374 |
Gear^.State:= Gear^.State or gstFalling |
|
66
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 |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
381 |
end; |
369 | 382 |
if (pX <> hwRound(Gear^.X)) and ((Gear^.State and gstFalling) = 0) then |
375 | 383 |
exit(true); |
369 | 384 |
until (pX = hwRound(Gear^.X)) and (pY = hwRound(Gear^.Y)) and ((Gear^.State and gstFalling) = 0); |
375 | 385 |
HHJump(AltGear, jmpHJump, GoInfo); |
386 |
HHGo:= Result |
|
4 | 387 |
end; |
388 |
||
371 | 389 |
function AIrndSign(num: LongInt): LongInt; |
136 | 390 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
391 |
if random(2) = 0 then AIrndSign:= num |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
392 |
else AIrndSign:= - num |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
393 |
end; |
136 | 394 |
|
4 | 395 |
end. |