author | unc0rr |
Thu, 20 Jul 2006 20:11:32 +0000 | |
changeset 80 | 3c3dc6a148ca |
parent 79 | 29b477319854 |
child 82 | 2f4f3236cccc |
permissions | -rw-r--r-- |
71 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
3 |
* Copyright (c) 2005, 2006 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 |
||
4 | 34 |
unit uAIMisc; |
35 |
interface |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
36 |
uses SDLh, uConsts, uGears; |
80 | 37 |
{$INCLUDE options.inc} |
4 | 38 |
|
64 | 39 |
type TTarget = record |
40 |
Point: TPoint; |
|
41 |
Score: integer; |
|
42 |
end; |
|
43 |
TTargets = record |
|
44 |
Count: Longword; |
|
45 |
ar: array[0..cMaxHHIndex*5] of TTarget; |
|
4 | 46 |
end; |
80 | 47 |
TJumpType = (jmpNone, jmpHJump, jmpLJump); |
75 | 48 |
TGoInfo = record |
49 |
Ticks: Longword; |
|
80 | 50 |
FallPix: Longword; |
51 |
JumpType: TJumpType; |
|
75 | 52 |
end; |
64 | 53 |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
54 |
procedure FillTargets; |
70 | 55 |
procedure FillBonuses(isAfterAttack: boolean); |
71 | 56 |
procedure AwareOfExplosion(x, y, r: integer); |
70 | 57 |
function RatePlace(Gear: PGear): integer; |
64 | 58 |
function DxDy2AttackAngle(const _dY, _dX: Extended): integer; |
4 | 59 |
function TestColl(x, y, r: integer): boolean; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
60 |
function RateExplosion(Me: PGear; x, y, r: integer): integer; |
79 | 61 |
function RateShove(Me: PGear; x, y, r, power: integer): integer; |
80 | 62 |
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
|
63 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
64 |
var ThinkingHH: PGear; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
65 |
Targets: TTargets; |
4 | 66 |
|
67 |
implementation |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
68 |
uses uTeams, uMisc, uLand, uCollisions; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
69 |
const KillScore = 200; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
70 |
MAXBONUS = 1024; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
71 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
72 |
type TBonus = record |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
73 |
X, Y: integer; |
70 | 74 |
Radius: integer; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
75 |
Score: integer; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
76 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
77 |
var bonuses: record |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
78 |
Count: Longword; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
79 |
ar: array[0..Pred(MAXBONUS)] of TBonus; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
80 |
end; |
71 | 81 |
KnownExplosion: record |
82 |
X, Y, Radius: integer |
|
83 |
end = (X: 0; Y: 0; Radius: 0); |
|
4 | 84 |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
85 |
procedure FillTargets; |
4 | 86 |
var t: PTeam; |
64 | 87 |
i: Longword; |
4 | 88 |
begin |
89 |
Targets.Count:= 0; |
|
90 |
t:= TeamsList; |
|
91 |
while t <> nil do |
|
92 |
begin |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
93 |
for i:= 0 to cMaxHHIndex do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
94 |
if (t.Hedgehogs[i].Gear <> nil) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
95 |
and (t.Hedgehogs[i].Gear <> ThinkingHH) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
96 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
97 |
with Targets.ar[Targets.Count], t.Hedgehogs[i] do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
98 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
99 |
Point.X:= Round(Gear.X); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
100 |
Point.Y:= Round(Gear.Y); |
74 | 101 |
if t.Color <> CurrentTeam.Color then Score:= Gear.Health |
102 |
else Score:= -Gear.Health |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
103 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
104 |
inc(Targets.Count) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
105 |
end; |
4 | 106 |
t:= t.Next |
64 | 107 |
end |
4 | 108 |
end; |
109 |
||
70 | 110 |
procedure FillBonuses(isAfterAttack: boolean); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
111 |
var Gear: PGear; |
70 | 112 |
MyColor: Longword; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
113 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
114 |
procedure AddBonus(x, y: integer; r: Longword; s: integer); |
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 |
bonuses.ar[bonuses.Count].x:= x; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
117 |
bonuses.ar[bonuses.Count].y:= y; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
118 |
bonuses.ar[bonuses.Count].Radius:= r; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
119 |
bonuses.ar[bonuses.Count].Score:= s; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
120 |
inc(bonuses.Count); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
121 |
TryDo(bonuses.Count <= MAXBONUS, 'Bonuses overflow', true) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
122 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
123 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
124 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
125 |
bonuses.Count:= 0; |
70 | 126 |
MyColor:= PHedgehog(ThinkingHH.Hedgehog).Team.Color; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
127 |
Gear:= GearsList; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
128 |
while Gear <> nil do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
129 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
130 |
case Gear.Kind of |
70 | 131 |
gtCase: AddBonus(round(Gear.X), round(Gear.Y), 33, 25); |
74 | 132 |
gtMine: if (Gear.State and gstAttacking) = 0 then AddBonus(round(Gear.X), round(Gear.Y), 50, -50) |
133 |
else AddBonus(round(Gear.X), round(Gear.Y), 100, -50); // mine is on |
|
70 | 134 |
gtDynamite: AddBonus(round(Gear.X), round(Gear.Y), 150, -75); |
135 |
gtHedgehog: begin |
|
74 | 136 |
if Gear.Damage >= Gear.Health then AddBonus(round(Gear.X), round(Gear.Y), 60, -25) else |
137 |
if isAfterAttack and (ThinkingHH.Hedgehog <> Gear.Hedgehog) then |
|
138 |
if (MyColor = PHedgehog(Gear.Hedgehog).Team.Color) then AddBonus(round(Gear.X), round(Gear.Y), 150, -3) // hedgehog-friend |
|
139 |
else AddBonus(round(Gear.X), round(Gear.Y), 100, 3) |
|
70 | 140 |
end; |
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 |
Gear:= Gear.NextGear |
71 | 143 |
end; |
144 |
if isAfterAttack and (KnownExplosion.Radius > 0) then |
|
145 |
with KnownExplosion do |
|
74 | 146 |
AddBonus(X, Y, Radius + 10, -Radius); |
71 | 147 |
end; |
148 |
||
149 |
procedure AwareOfExplosion(x, y, r: integer); |
|
150 |
begin |
|
151 |
KnownExplosion.X:= x; |
|
152 |
KnownExplosion.Y:= y; |
|
153 |
KnownExplosion.Radius:= r |
|
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 |
|
70 | 156 |
function RatePlace(Gear: PGear): integer; |
157 |
var i, r: integer; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
158 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
159 |
Result:= 0; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
160 |
for i:= 0 to Pred(bonuses.Count) do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
161 |
with bonuses.ar[i] do |
70 | 162 |
begin |
163 |
r:= round(sqrt(sqr(Gear.X - X) + sqr(Gear.Y - y))); |
|
164 |
if r < Radius then |
|
165 |
inc(Result, Score * (Radius - r)) |
|
166 |
end; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
167 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
168 |
|
64 | 169 |
function DxDy2AttackAngle(const _dY, _dX: Extended): integer; |
4 | 170 |
const piDIVMaxAngle: Extended = pi/cMaxAngle; |
171 |
asm |
|
172 |
fld _dY |
|
173 |
fld _dX |
|
174 |
fpatan |
|
175 |
fld piDIVMaxAngle |
|
176 |
fdiv |
|
177 |
sub esp, 4 |
|
178 |
fistp dword ptr [esp] |
|
179 |
pop eax |
|
180 |
end; |
|
181 |
||
182 |
function TestColl(x, y, r: integer): boolean; |
|
183 |
begin |
|
184 |
Result:=(((x-r) and $FFFFF800) = 0)and(((y-r) and $FFFFFC00) = 0) and (Land[y-r, x-r] <> 0); |
|
185 |
if Result then exit; |
|
186 |
Result:=(((x-r) and $FFFFF800) = 0)and(((y+r) and $FFFFFC00) = 0) and (Land[y+r, x-r] <> 0); |
|
187 |
if Result then exit; |
|
188 |
Result:=(((x+r) and $FFFFF800) = 0)and(((y-r) and $FFFFFC00) = 0) and (Land[y-r, x+r] <> 0); |
|
189 |
if Result then exit; |
|
190 |
Result:=(((x+r) and $FFFFF800) = 0)and(((y+r) and $FFFFFC00) = 0) and (Land[y+r, x+r] <> 0); |
|
191 |
end; |
|
192 |
||
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
193 |
function RateExplosion(Me: PGear; x, y, r: integer): integer; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
194 |
var i, dmg: integer; |
4 | 195 |
begin |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
196 |
Result:= 0; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
197 |
// add our virtual position |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
198 |
with Targets.ar[Targets.Count] do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
199 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
200 |
Point.x:= round(Me.X); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
201 |
Point.y:= round(Me.Y); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
202 |
Score:= - ThinkingHH.Health |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
203 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
204 |
// rate explosion |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
205 |
for i:= 0 to Targets.Count do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
206 |
with Targets.ar[i] do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
207 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
208 |
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
|
209 |
if dmg > 0 then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
210 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
211 |
dmg:= dmg shr 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
212 |
if dmg > abs(Score) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
213 |
if Score > 0 then inc(Result, KillScore) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
214 |
else dec(Result, KillScore * 3) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
215 |
else |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
216 |
if Score > 0 then inc(Result, dmg) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
217 |
else dec(Result, dmg * 3) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
218 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
219 |
end; |
70 | 220 |
Result:= Result * 1024 |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
221 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
222 |
|
79 | 223 |
function RateShove(Me: PGear; x, y, r, power: integer): integer; |
224 |
var i, dmg: integer; |
|
225 |
begin |
|
226 |
Result:= 0; |
|
227 |
for i:= 0 to Targets.Count do |
|
228 |
with Targets.ar[i] do |
|
229 |
begin |
|
230 |
dmg:= r - Round(sqrt(sqr(Point.x - x) + sqr(Point.y - y))); |
|
231 |
if dmg > 0 then |
|
232 |
begin |
|
233 |
if power > abs(Score) then |
|
234 |
if Score > 0 then inc(Result, KillScore) |
|
235 |
else dec(Result, KillScore * 3) |
|
236 |
else |
|
237 |
if Score > 0 then inc(Result, power) |
|
238 |
else dec(Result, power * 3) |
|
239 |
end; |
|
240 |
end; |
|
241 |
Result:= Result * 1024 |
|
242 |
end; |
|
243 |
||
80 | 244 |
function HHJump(Gear: PGear; JumpType: TJumpType; out GoInfo: TGoInfo): boolean; |
245 |
var bX, bY: integer; |
|
246 |
begin |
|
247 |
Result:= false; |
|
248 |
GoInfo.Ticks:= 0; |
|
249 |
GoInfo.FallPix:= 0; |
|
250 |
GoInfo.JumpType:= jmpNone; |
|
251 |
bX:= round(Gear.X); |
|
252 |
bY:= round(Gear.Y); |
|
253 |
case JumpType of |
|
254 |
jmpNone: exit; |
|
255 |
jmpHJump: if not TestCollisionYwithGear(Gear, -1) then |
|
256 |
begin |
|
257 |
Gear.dY:= -0.20; |
|
258 |
Gear.dX:= 0.0000001 * Sign(Gear.dX); |
|
259 |
Gear.X:= Gear.X - Sign(Gear.dX)*0.00008; // shift compensation |
|
260 |
Gear.State:= Gear.State or gstFalling or gstHHJumping; |
|
261 |
end else exit; |
|
262 |
jmpLJump: begin |
|
263 |
if not TestCollisionYwithGear(Gear, -1) then |
|
264 |
if not TestCollisionXwithXYShift(Gear, 0, -2, Sign(Gear.dX)) then Gear.Y:= Gear.Y - 2 else |
|
265 |
if not TestCollisionXwithXYShift(Gear, 0, -1, Sign(Gear.dX)) then Gear.Y:= Gear.Y - 1; |
|
266 |
if not (TestCollisionXwithGear(Gear, Sign(Gear.dX)) |
|
267 |
or TestCollisionYwithGear(Gear, -1)) then |
|
268 |
begin |
|
269 |
Gear.dY:= -0.15; |
|
270 |
Gear.dX:= Sign(Gear.dX) * 0.15; |
|
271 |
Gear.State:= Gear.State or gstFalling or gstHHJumping |
|
272 |
end |
|
273 |
end |
|
274 |
end; |
|
275 |
||
276 |
repeat |
|
277 |
if Gear.Y + cHHRadius >= cWaterLine then exit; |
|
278 |
if (Gear.State and gstFalling) <> 0 then |
|
279 |
begin |
|
280 |
if (GoInfo.Ticks = 350) then |
|
281 |
if (abs(Gear.dX) < 0.0000002) and (Gear.dY < -0.02) then |
|
282 |
begin |
|
283 |
Gear.dY:= -0.25; |
|
284 |
Gear.dX:= Sign(Gear.dX) * 0.02 |
|
285 |
end; |
|
286 |
if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then Gear.dX:= 0.0000001 * Sign(Gear.dX); |
|
287 |
Gear.X:= Gear.X + Gear.dX; |
|
288 |
inc(GoInfo.Ticks); |
|
289 |
Gear.dY:= Gear.dY + cGravity; |
|
290 |
if Gear.dY > 0.40 then exit; |
|
291 |
if (Gear.dY < 0)and TestCollisionYwithGear(Gear, -1) then Gear.dY:= 0; |
|
292 |
Gear.Y:= Gear.Y + Gear.dY; |
|
293 |
if (Gear.dY >= 0)and TestCollisionYwithGear(Gear, 1) then |
|
294 |
begin |
|
295 |
Gear.State:= Gear.State and not (gstFalling or gstHHJumping); |
|
296 |
Gear.dY:= 0; |
|
297 |
case JumpType of |
|
298 |
jmpHJump: if (bY - Gear.Y > 5) then |
|
299 |
begin |
|
300 |
Result:= true; |
|
301 |
GoInfo.JumpType:= jmpHJump; |
|
302 |
inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after |
|
303 |
end; |
|
304 |
jmpLJump: if abs(bX - Gear.X) > 30 then |
|
305 |
begin |
|
306 |
Result:= true; |
|
307 |
GoInfo.JumpType:= jmpLJump; |
|
308 |
inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after |
|
309 |
end; |
|
310 |
end; |
|
311 |
exit |
|
312 |
end; |
|
313 |
end; |
|
314 |
until false; |
|
315 |
end; |
|
316 |
||
317 |
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
|
318 |
var pX, pY: integer; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
319 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
320 |
Result:= false; |
80 | 321 |
AltGear^:= Gear^; |
322 |
||
75 | 323 |
GoInfo.Ticks:= 0; |
80 | 324 |
GoInfo.FallPix:= 0; |
325 |
GoInfo.JumpType:= jmpNone; |
|
4 | 326 |
repeat |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
327 |
pX:= round(Gear.X); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
328 |
pY:= round(Gear.Y); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
329 |
if pY + cHHRadius >= cWaterLine then exit; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
330 |
if (Gear.State and gstFalling) <> 0 then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
331 |
begin |
75 | 332 |
inc(GoInfo.Ticks); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
333 |
Gear.dY:= Gear.dY + cGravity; |
75 | 334 |
if Gear.dY > 0.40 then |
335 |
begin |
|
80 | 336 |
Goinfo.FallPix:= 0; |
337 |
HHJump(AltGear, jmpLJump, GoInfo); |
|
75 | 338 |
exit |
339 |
end; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
340 |
Gear.Y:= Gear.Y + Gear.dY; |
80 | 341 |
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
|
342 |
if TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
343 |
begin |
75 | 344 |
inc(GoInfo.Ticks, 300); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
345 |
Gear.State:= Gear.State and not (gstFalling or gstHHJumping); |
75 | 346 |
Gear.dY:= 0; |
347 |
Result:= true; |
|
80 | 348 |
HHJump(AltGear, jmpLJump, GoInfo); |
75 | 349 |
exit |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
350 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
351 |
continue |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
352 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
353 |
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
|
354 |
if (Gear.Message and gm_Right )<>0 then Gear.dX:= 1.0 else exit; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
355 |
if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
356 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
357 |
if not (TestCollisionXwithXYShift(Gear, 0, -6, Sign(Gear.dX)) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
358 |
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
|
359 |
if not (TestCollisionXwithXYShift(Gear, 0, -5, Sign(Gear.dX)) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
360 |
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
|
361 |
if not (TestCollisionXwithXYShift(Gear, 0, -4, Sign(Gear.dX)) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
362 |
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
|
363 |
if not (TestCollisionXwithXYShift(Gear, 0, -3, Sign(Gear.dX)) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
364 |
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
|
365 |
if not (TestCollisionXwithXYShift(Gear, 0, -2, Sign(Gear.dX)) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
366 |
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
|
367 |
if not (TestCollisionXwithXYShift(Gear, 0, -1, Sign(Gear.dX)) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
368 |
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
|
369 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
370 |
|
75 | 371 |
if not TestCollisionXwithGear(Gear, Sign(Gear.dX)) then |
372 |
begin |
|
373 |
Gear.X:= Gear.X + Gear.dX; |
|
374 |
inc(GoInfo.Ticks, cHHStepTicks) |
|
375 |
end; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
376 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
377 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
378 |
Gear.Y:= Gear.Y + 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
379 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
380 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
381 |
Gear.Y:= Gear.Y + 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
382 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
383 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
384 |
Gear.Y:= Gear.Y + 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
385 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
386 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
387 |
Gear.Y:= Gear.Y + 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
388 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
389 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
390 |
Gear.Y:= Gear.Y + 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
391 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
392 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
393 |
Gear.Y:= Gear.Y + 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
394 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
395 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
396 |
Gear.Y:= Gear.Y - 6; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
397 |
Gear.dY:= 0; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
398 |
Gear.dX:= 0.0000001 * Sign(Gear.dX); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
399 |
Gear.State:= Gear.State or gstFalling |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
400 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
401 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
402 |
end |
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; |
75 | 407 |
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
|
408 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
409 |
Result:= true; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
410 |
exit |
75 | 411 |
end |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
412 |
until (pX = round(Gear.X)) and (pY = round(Gear.Y)) and ((Gear.State and gstFalling) = 0); |
80 | 413 |
HHJump(AltGear, jmpHJump, GoInfo) |
4 | 414 |
end; |
415 |
||
416 |
end. |