author | unc0rr |
Thu, 01 May 2008 14:30:12 +0000 | |
changeset 894 | 2ca76a7f3121 |
parent 883 | 07a568ba44e0 |
child 921 | 8dd71d960cbc |
permissions | -rw-r--r-- |
71 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
883 | 3 |
* Copyright (c) 2005-2008 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; |
|
509 | 46 |
function RateShotgun(Me: PGear; x, y: LongInt): LongInt; |
369 | 47 |
function HHGo(Gear, AltGear: PGear; var GoInfo: TGoInfo): boolean; |
371 | 48 |
function AIrndSign(num: LongInt): LongInt; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
49 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
50 |
var ThinkingHH: PGear; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
51 |
Targets: TTargets; |
369 | 52 |
|
4 | 53 |
implementation |
369 | 54 |
uses uTeams, uMisc, uLand, uCollisions; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
55 |
const KillScore = 200; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
56 |
MAXBONUS = 1024; |
369 | 57 |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
58 |
type TBonus = record |
371 | 59 |
X, Y: LongInt; |
60 |
Radius: LongInt; |
|
61 |
Score: LongInt; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
62 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
63 |
var bonuses: record |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
64 |
Count: Longword; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
65 |
ar: array[0..Pred(MAXBONUS)] of TBonus; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
66 |
end; |
71 | 67 |
KnownExplosion: record |
371 | 68 |
X, Y, Radius: LongInt |
71 | 69 |
end = (X: 0; Y: 0; Radius: 0); |
4 | 70 |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
71 |
procedure FillTargets; |
547 | 72 |
var i, t: Longword; |
4 | 73 |
begin |
74 |
Targets.Count:= 0; |
|
547 | 75 |
for t:= 0 to Pred(TeamsCount) do |
76 |
with TeamsArray[t]^ do |
|
4 | 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 |
547 | 79 |
if (Hedgehogs[i].Gear <> nil) |
80 |
and (Hedgehogs[i].Gear <> ThinkingHH) then |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
81 |
begin |
547 | 82 |
with Targets.ar[Targets.Count], 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); |
|
549 | 86 |
if Clan <> CurrentTeam^.Clan 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; |
64 | 91 |
end |
4 | 92 |
end; |
93 |
||
70 | 94 |
procedure FillBonuses(isAfterAttack: boolean); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
95 |
var Gear: PGear; |
549 | 96 |
MyClan: PClan; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
97 |
|
371 | 98 |
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
|
99 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
100 |
bonuses.ar[bonuses.Count].x:= x; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
101 |
bonuses.ar[bonuses.Count].y:= y; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
102 |
bonuses.ar[bonuses.Count].Radius:= r; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
103 |
bonuses.ar[bonuses.Count].Score:= s; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
104 |
inc(bonuses.Count); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
105 |
TryDo(bonuses.Count <= MAXBONUS, 'Bonuses overflow', true) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
106 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
107 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
108 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
109 |
bonuses.Count:= 0; |
549 | 110 |
MyClan:= PHedgehog(ThinkingHH^.Hedgehog)^.Team^.Clan; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
111 |
Gear:= GearsList; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
112 |
while Gear <> nil do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
113 |
begin |
369 | 114 |
case Gear^.Kind of |
115 |
gtCase: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 33, 25); |
|
116 |
gtMine: if (Gear^.State and gstAttacking) = 0 then AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 50, -50) |
|
117 |
else AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, -50); // mine is on |
|
118 |
gtDynamite: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -75); |
|
70 | 119 |
gtHedgehog: begin |
369 | 120 |
if Gear^.Damage >= Gear^.Health then AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 60, -25) else |
121 |
if isAfterAttack and (ThinkingHH^.Hedgehog <> Gear^.Hedgehog) then |
|
549 | 122 |
if (MyClan = PHedgehog(Gear^.Hedgehog)^.Team^.Clan) then AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -3) // hedgehog-friend |
123 |
else AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, 3) |
|
70 | 124 |
end; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
125 |
end; |
369 | 126 |
Gear:= Gear^.NextGear |
71 | 127 |
end; |
128 |
if isAfterAttack and (KnownExplosion.Radius > 0) then |
|
129 |
with KnownExplosion do |
|
74 | 130 |
AddBonus(X, Y, Radius + 10, -Radius); |
71 | 131 |
end; |
132 |
||
371 | 133 |
procedure AwareOfExplosion(x, y, r: LongInt); |
71 | 134 |
begin |
135 |
KnownExplosion.X:= x; |
|
136 |
KnownExplosion.Y:= y; |
|
137 |
KnownExplosion.Radius:= r |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
138 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
139 |
|
371 | 140 |
function RatePlace(Gear: PGear): LongInt; |
141 |
var i, r: LongInt; |
|
142 |
Result: LongInt; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
143 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
144 |
Result:= 0; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
145 |
for i:= 0 to Pred(bonuses.Count) do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
146 |
with bonuses.ar[i] do |
70 | 147 |
begin |
498 | 148 |
r:= hwRound(Distance(Gear^.X - int2hwFloat(X), Gear^.Y - int2hwFloat(Y))); |
70 | 149 |
if r < Radius then |
150 |
inc(Result, Score * (Radius - r)) |
|
151 |
end; |
|
369 | 152 |
RatePlace:= Result |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
153 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
154 |
|
371 | 155 |
function TestColl(x, y, r: LongInt): boolean; |
369 | 156 |
var b: boolean; |
4 | 157 |
begin |
369 | 158 |
b:= (((x-r) and $FFFFF800) = 0)and(((y-r) and $FFFFFC00) = 0) and (Land[y-r, x-r] <> 0); |
159 |
if b then exit(true); |
|
160 |
b:=(((x-r) and $FFFFF800) = 0)and(((y+r) and $FFFFFC00) = 0) and (Land[y+r, x-r] <> 0); |
|
161 |
if b then exit(true); |
|
162 |
b:=(((x+r) and $FFFFF800) = 0)and(((y-r) and $FFFFFC00) = 0) and (Land[y-r, x+r] <> 0); |
|
163 |
if b then exit(true); |
|
164 |
TestColl:=(((x+r) and $FFFFF800) = 0)and(((y+r) and $FFFFFC00) = 0) and (Land[y+r, x+r] <> 0) |
|
4 | 165 |
end; |
166 |
||
371 | 167 |
function RateExplosion(Me: PGear; x, y, r: LongInt): LongInt; |
168 |
var i, dmg, Result: LongInt; |
|
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 |
369 | 174 |
Point.x:= hwRound(Me^.X); |
175 |
Point.y:= hwRound(Me^.Y); |
|
176 |
Score:= - ThinkingHH^.Health |
|
66
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 |
498 | 182 |
dmg:= r - hwRound(DistanceI(Point.x - x, Point.y - y)); |
66
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; |
509 | 186 |
if dmg >= abs(Score) then |
66
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; |
369 | 194 |
RateExplosion:= 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 |
|
371 | 197 |
function RateShove(Me: PGear; x, y, r, power: LongInt): LongInt; |
198 |
var i, dmg, Result: LongInt; |
|
79 | 199 |
begin |
200 |
Result:= 0; |
|
433 | 201 |
for i:= 0 to Pred(Targets.Count) do |
79 | 202 |
with Targets.ar[i] do |
203 |
begin |
|
498 | 204 |
dmg:= r - hwRound(DistanceI(Point.x - x, Point.y - y)); |
79 | 205 |
if dmg > 0 then |
206 |
begin |
|
509 | 207 |
if power >= abs(Score) then |
79 | 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; |
|
369 | 215 |
RateShove:= Result * 1024 |
79 | 216 |
end; |
217 |
||
509 | 218 |
function RateShotgun(Me: PGear; x, y: LongInt): LongInt; |
219 |
var i, dmg, Result: LongInt; |
|
220 |
begin |
|
221 |
Result:= 0; |
|
222 |
// add our virtual position |
|
223 |
with Targets.ar[Targets.Count] do |
|
224 |
begin |
|
225 |
Point.x:= hwRound(Me^.X); |
|
226 |
Point.y:= hwRound(Me^.Y); |
|
227 |
Score:= - ThinkingHH^.Health |
|
228 |
end; |
|
229 |
// rate shot |
|
230 |
for i:= 0 to Targets.Count do |
|
231 |
with Targets.ar[i] do |
|
232 |
begin |
|
233 |
dmg:= min(cHHRadius + cShotgunRadius - hwRound(DistanceI(Point.x - x, Point.y - y)), 25); |
|
234 |
if dmg > 0 then |
|
235 |
begin |
|
236 |
if dmg >= abs(Score) then |
|
237 |
if Score > 0 then inc(Result, KillScore) |
|
238 |
else dec(Result, KillScore * 3) |
|
239 |
else |
|
240 |
if Score > 0 then inc(Result, dmg) |
|
241 |
else dec(Result, dmg * 3) |
|
242 |
end; |
|
243 |
end; |
|
244 |
RateShotgun:= Result * 1024 |
|
245 |
end; |
|
246 |
||
369 | 247 |
function HHJump(Gear: PGear; JumpType: TJumpType; var GoInfo: TGoInfo): boolean; |
371 | 248 |
var bX, bY: LongInt; |
369 | 249 |
Result: boolean; |
80 | 250 |
begin |
251 |
Result:= false; |
|
252 |
GoInfo.Ticks:= 0; |
|
253 |
GoInfo.FallPix:= 0; |
|
254 |
GoInfo.JumpType:= jmpNone; |
|
369 | 255 |
bX:= hwRound(Gear^.X); |
256 |
bY:= hwRound(Gear^.Y); |
|
80 | 257 |
case JumpType of |
369 | 258 |
jmpNone: exit(Result); |
80 | 259 |
jmpHJump: if not TestCollisionYwithGear(Gear, -1) then |
260 |
begin |
|
369 | 261 |
Gear^.dY:= -_0_2; |
262 |
SetLittle(Gear^.dX); |
|
542 | 263 |
Gear^.State:= Gear^.State or gstMoving or gstHHJumping; |
369 | 264 |
end else exit(Result); |
80 | 265 |
jmpLJump: begin |
266 |
if not TestCollisionYwithGear(Gear, -1) then |
|
498 | 267 |
if not TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX)) then Gear^.Y:= Gear^.Y - int2hwFloat(2) else |
268 |
if not TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX)) then Gear^.Y:= Gear^.Y - _1; |
|
369 | 269 |
if not (TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) |
80 | 270 |
or TestCollisionYwithGear(Gear, -1)) then |
271 |
begin |
|
433 | 272 |
Gear^.dY:= -_0_15; |
498 | 273 |
Gear^.dX:= SignAs(_0_15, Gear^.dX); |
542 | 274 |
Gear^.State:= Gear^.State or gstMoving or gstHHJumping |
369 | 275 |
end else exit(Result) |
80 | 276 |
end |
277 |
end; |
|
278 |
||
279 |
repeat |
|
498 | 280 |
if not (hwRound(Gear^.Y) + cHHRadius < cWaterLine) then exit(Result); |
542 | 281 |
if (Gear^.State and gstMoving) <> 0 then |
80 | 282 |
begin |
283 |
if (GoInfo.Ticks = 350) then |
|
433 | 284 |
if (not (hwAbs(Gear^.dX) > cLittle)) and (Gear^.dY < -_0_02) then |
80 | 285 |
begin |
369 | 286 |
Gear^.dY:= -_0_25; |
498 | 287 |
Gear^.dX:= SignAs(_0_02, Gear^.dX) |
80 | 288 |
end; |
369 | 289 |
if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then SetLittle(Gear^.dX); |
290 |
Gear^.X:= Gear^.X + Gear^.dX; |
|
80 | 291 |
inc(GoInfo.Ticks); |
369 | 292 |
Gear^.dY:= Gear^.dY + cGravity; |
293 |
if Gear^.dY > _0_4 then exit(Result); |
|
498 | 294 |
if (Gear^.dY.isNegative)and TestCollisionYwithGear(Gear, -1) then Gear^.dY:= _0; |
369 | 295 |
Gear^.Y:= Gear^.Y + Gear^.dY; |
296 |
if (not Gear^.dY.isNegative)and TestCollisionYwithGear(Gear, 1) then |
|
80 | 297 |
begin |
542 | 298 |
Gear^.State:= Gear^.State and not (gstMoving or gstHHJumping); |
498 | 299 |
Gear^.dY:= _0; |
80 | 300 |
case JumpType of |
498 | 301 |
jmpHJump: if bY - hwRound(Gear^.Y) > 5 then |
80 | 302 |
begin |
303 |
Result:= true; |
|
304 |
GoInfo.JumpType:= jmpHJump; |
|
305 |
inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after |
|
306 |
end; |
|
498 | 307 |
jmpLJump: if abs(bX - hwRound(Gear^.X)) > 30 then |
80 | 308 |
begin |
309 |
Result:= true; |
|
310 |
GoInfo.JumpType:= jmpLJump; |
|
311 |
inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after |
|
312 |
end; |
|
313 |
end; |
|
369 | 314 |
exit(Result) |
80 | 315 |
end; |
316 |
end; |
|
369 | 317 |
until false |
80 | 318 |
end; |
319 |
||
369 | 320 |
function HHGo(Gear, AltGear: PGear; var GoInfo: TGoInfo): boolean; |
371 | 321 |
var pX, pY: LongInt; |
369 | 322 |
Result: boolean; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
323 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
324 |
Result:= false; |
80 | 325 |
AltGear^:= Gear^; |
326 |
||
75 | 327 |
GoInfo.Ticks:= 0; |
80 | 328 |
GoInfo.FallPix:= 0; |
329 |
GoInfo.JumpType:= jmpNone; |
|
4 | 330 |
repeat |
369 | 331 |
pX:= hwRound(Gear^.X); |
332 |
pY:= hwRound(Gear^.Y); |
|
375 | 333 |
if pY + cHHRadius >= cWaterLine then exit(false); |
542 | 334 |
if (Gear^.State and gstMoving) <> 0 then |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
335 |
begin |
75 | 336 |
inc(GoInfo.Ticks); |
369 | 337 |
Gear^.dY:= Gear^.dY + cGravity; |
338 |
if Gear^.dY > _0_4 then |
|
75 | 339 |
begin |
80 | 340 |
Goinfo.FallPix:= 0; |
568 | 341 |
HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall with damage |
369 | 342 |
exit(Result) |
75 | 343 |
end; |
369 | 344 |
Gear^.Y:= Gear^.Y + Gear^.dY; |
345 |
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
|
346 |
if TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
347 |
begin |
75 | 348 |
inc(GoInfo.Ticks, 300); |
542 | 349 |
Gear^.State:= Gear^.State and not (gstMoving or gstHHJumping); |
498 | 350 |
Gear^.dY:= _0; |
75 | 351 |
Result:= true; |
82 | 352 |
HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall |
369 | 353 |
exit(Result) |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
354 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
355 |
continue |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
356 |
end; |
369 | 357 |
if (Gear^.Message and gm_Left )<>0 then Gear^.dX:= -cLittle else |
358 |
if (Gear^.Message and gm_Right )<>0 then Gear^.dX:= cLittle else exit(Result); |
|
359 |
if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
360 |
begin |
498 | 361 |
if not (TestCollisionXwithXYShift(Gear, _0, -6, hwSign(Gear^.dX)) |
362 |
or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; |
|
363 |
if not (TestCollisionXwithXYShift(Gear, _0, -5, hwSign(Gear^.dX)) |
|
364 |
or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; |
|
365 |
if not (TestCollisionXwithXYShift(Gear, _0, -4, hwSign(Gear^.dX)) |
|
366 |
or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; |
|
367 |
if not (TestCollisionXwithXYShift(Gear, _0, -3, hwSign(Gear^.dX)) |
|
368 |
or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; |
|
369 |
if not (TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX)) |
|
370 |
or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; |
|
371 |
if not (TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX)) |
|
372 |
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
|
373 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
374 |
|
369 | 375 |
if not TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then |
75 | 376 |
begin |
498 | 377 |
Gear^.X:= Gear^.X + int2hwFloat(hwSign(Gear^.dX)); |
75 | 378 |
inc(GoInfo.Ticks, cHHStepTicks) |
379 |
end; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
380 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
381 |
begin |
498 | 382 |
Gear^.Y:= Gear^.Y + _1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
383 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
384 |
begin |
498 | 385 |
Gear^.Y:= Gear^.Y + _1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
386 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
387 |
begin |
498 | 388 |
Gear^.Y:= Gear^.Y + _1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
389 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
390 |
begin |
498 | 391 |
Gear^.Y:= Gear^.Y + _1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
392 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
393 |
begin |
498 | 394 |
Gear^.Y:= Gear^.Y + _1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
395 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
396 |
begin |
498 | 397 |
Gear^.Y:= Gear^.Y + _1; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
398 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
399 |
begin |
498 | 400 |
Gear^.Y:= Gear^.Y - _6; |
401 |
Gear^.dY:= _0; |
|
542 | 402 |
Gear^.State:= Gear^.State or gstMoving |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
403 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
404 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
405 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
406 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
407 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
408 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
409 |
end; |
542 | 410 |
if (pX <> hwRound(Gear^.X)) and ((Gear^.State and gstMoving) = 0) then |
375 | 411 |
exit(true); |
542 | 412 |
until (pX = hwRound(Gear^.X)) and (pY = hwRound(Gear^.Y)) and ((Gear^.State and gstMoving) = 0); |
375 | 413 |
HHJump(AltGear, jmpHJump, GoInfo); |
414 |
HHGo:= Result |
|
4 | 415 |
end; |
416 |
||
371 | 417 |
function AIrndSign(num: LongInt): LongInt; |
136 | 418 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
419 |
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
|
420 |
else AIrndSign:= - num |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
421 |
end; |
136 | 422 |
|
4 | 423 |
end. |