author | unc0rr |
Sun, 16 Jul 2006 08:13:51 +0000 | |
changeset 79 | 29b477319854 |
parent 75 | d2b737858ff7 |
child 80 | 3c3dc6a148ca |
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; |
4 | 37 |
|
64 | 38 |
type TTarget = record |
39 |
Point: TPoint; |
|
40 |
Score: integer; |
|
41 |
end; |
|
42 |
TTargets = record |
|
43 |
Count: Longword; |
|
44 |
ar: array[0..cMaxHHIndex*5] of TTarget; |
|
4 | 45 |
end; |
75 | 46 |
TGoInfo = record |
47 |
Ticks: Longword; |
|
48 |
FallTicks: Longword; |
|
49 |
end; |
|
64 | 50 |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
51 |
procedure FillTargets; |
70 | 52 |
procedure FillBonuses(isAfterAttack: boolean); |
71 | 53 |
procedure AwareOfExplosion(x, y, r: integer); |
70 | 54 |
function RatePlace(Gear: PGear): integer; |
64 | 55 |
function DxDy2AttackAngle(const _dY, _dX: Extended): integer; |
4 | 56 |
function TestColl(x, y, r: integer): boolean; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
57 |
function RateExplosion(Me: PGear; x, y, r: integer): integer; |
79 | 58 |
function RateShove(Me: PGear; x, y, r, power: integer): integer; |
75 | 59 |
function HHGo(Gear: PGear; out GoInfo: TGoInfo): boolean; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
60 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
61 |
var ThinkingHH: PGear; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
62 |
Targets: TTargets; |
4 | 63 |
|
64 |
implementation |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
65 |
uses uTeams, uMisc, uLand, uCollisions; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
66 |
const KillScore = 200; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
67 |
MAXBONUS = 1024; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
68 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
69 |
type TBonus = record |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
70 |
X, Y: integer; |
70 | 71 |
Radius: integer; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
72 |
Score: integer; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
73 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
74 |
var bonuses: record |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
75 |
Count: Longword; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
76 |
ar: array[0..Pred(MAXBONUS)] of TBonus; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
77 |
end; |
71 | 78 |
KnownExplosion: record |
79 |
X, Y, Radius: integer |
|
80 |
end = (X: 0; Y: 0; Radius: 0); |
|
4 | 81 |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
82 |
procedure FillTargets; |
4 | 83 |
var t: PTeam; |
64 | 84 |
i: Longword; |
4 | 85 |
begin |
86 |
Targets.Count:= 0; |
|
87 |
t:= TeamsList; |
|
88 |
while t <> nil do |
|
89 |
begin |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
90 |
for i:= 0 to cMaxHHIndex do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
91 |
if (t.Hedgehogs[i].Gear <> nil) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
92 |
and (t.Hedgehogs[i].Gear <> ThinkingHH) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
93 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
94 |
with Targets.ar[Targets.Count], t.Hedgehogs[i] do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
95 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
96 |
Point.X:= Round(Gear.X); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
97 |
Point.Y:= Round(Gear.Y); |
74 | 98 |
if t.Color <> CurrentTeam.Color then Score:= Gear.Health |
99 |
else Score:= -Gear.Health |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
100 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
101 |
inc(Targets.Count) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
102 |
end; |
4 | 103 |
t:= t.Next |
64 | 104 |
end |
4 | 105 |
end; |
106 |
||
70 | 107 |
procedure FillBonuses(isAfterAttack: boolean); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
108 |
var Gear: PGear; |
70 | 109 |
MyColor: Longword; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
110 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
111 |
procedure AddBonus(x, y: integer; r: Longword; s: integer); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
112 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
113 |
bonuses.ar[bonuses.Count].x:= x; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
114 |
bonuses.ar[bonuses.Count].y:= y; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
115 |
bonuses.ar[bonuses.Count].Radius:= r; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
116 |
bonuses.ar[bonuses.Count].Score:= s; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
117 |
inc(bonuses.Count); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
118 |
TryDo(bonuses.Count <= MAXBONUS, 'Bonuses overflow', true) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
119 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
120 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
121 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
122 |
bonuses.Count:= 0; |
70 | 123 |
MyColor:= PHedgehog(ThinkingHH.Hedgehog).Team.Color; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
124 |
Gear:= GearsList; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
125 |
while Gear <> nil do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
126 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
127 |
case Gear.Kind of |
70 | 128 |
gtCase: AddBonus(round(Gear.X), round(Gear.Y), 33, 25); |
74 | 129 |
gtMine: if (Gear.State and gstAttacking) = 0 then AddBonus(round(Gear.X), round(Gear.Y), 50, -50) |
130 |
else AddBonus(round(Gear.X), round(Gear.Y), 100, -50); // mine is on |
|
70 | 131 |
gtDynamite: AddBonus(round(Gear.X), round(Gear.Y), 150, -75); |
132 |
gtHedgehog: begin |
|
74 | 133 |
if Gear.Damage >= Gear.Health then AddBonus(round(Gear.X), round(Gear.Y), 60, -25) else |
134 |
if isAfterAttack and (ThinkingHH.Hedgehog <> Gear.Hedgehog) then |
|
135 |
if (MyColor = PHedgehog(Gear.Hedgehog).Team.Color) then AddBonus(round(Gear.X), round(Gear.Y), 150, -3) // hedgehog-friend |
|
136 |
else AddBonus(round(Gear.X), round(Gear.Y), 100, 3) |
|
70 | 137 |
end; |
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 |
Gear:= Gear.NextGear |
71 | 140 |
end; |
141 |
if isAfterAttack and (KnownExplosion.Radius > 0) then |
|
142 |
with KnownExplosion do |
|
74 | 143 |
AddBonus(X, Y, Radius + 10, -Radius); |
71 | 144 |
end; |
145 |
||
146 |
procedure AwareOfExplosion(x, y, r: integer); |
|
147 |
begin |
|
148 |
KnownExplosion.X:= x; |
|
149 |
KnownExplosion.Y:= y; |
|
150 |
KnownExplosion.Radius:= r |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
151 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
152 |
|
70 | 153 |
function RatePlace(Gear: PGear): integer; |
154 |
var i, r: integer; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
155 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
156 |
Result:= 0; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
157 |
for i:= 0 to Pred(bonuses.Count) do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
158 |
with bonuses.ar[i] do |
70 | 159 |
begin |
160 |
r:= round(sqrt(sqr(Gear.X - X) + sqr(Gear.Y - y))); |
|
161 |
if r < Radius then |
|
162 |
inc(Result, Score * (Radius - r)) |
|
163 |
end; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
164 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
165 |
|
64 | 166 |
function DxDy2AttackAngle(const _dY, _dX: Extended): integer; |
4 | 167 |
const piDIVMaxAngle: Extended = pi/cMaxAngle; |
168 |
asm |
|
169 |
fld _dY |
|
170 |
fld _dX |
|
171 |
fpatan |
|
172 |
fld piDIVMaxAngle |
|
173 |
fdiv |
|
174 |
sub esp, 4 |
|
175 |
fistp dword ptr [esp] |
|
176 |
pop eax |
|
177 |
end; |
|
178 |
||
179 |
function TestColl(x, y, r: integer): boolean; |
|
180 |
begin |
|
181 |
Result:=(((x-r) and $FFFFF800) = 0)and(((y-r) and $FFFFFC00) = 0) and (Land[y-r, x-r] <> 0); |
|
182 |
if Result then exit; |
|
183 |
Result:=(((x-r) and $FFFFF800) = 0)and(((y+r) and $FFFFFC00) = 0) and (Land[y+r, x-r] <> 0); |
|
184 |
if Result then exit; |
|
185 |
Result:=(((x+r) and $FFFFF800) = 0)and(((y-r) and $FFFFFC00) = 0) and (Land[y-r, x+r] <> 0); |
|
186 |
if Result then exit; |
|
187 |
Result:=(((x+r) and $FFFFF800) = 0)and(((y+r) and $FFFFFC00) = 0) and (Land[y+r, x+r] <> 0); |
|
188 |
end; |
|
189 |
||
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
190 |
function RateExplosion(Me: PGear; x, y, r: integer): integer; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
191 |
var i, dmg: integer; |
4 | 192 |
begin |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
193 |
Result:= 0; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
194 |
// add our virtual position |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
195 |
with Targets.ar[Targets.Count] do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
196 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
197 |
Point.x:= round(Me.X); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
198 |
Point.y:= round(Me.Y); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
199 |
Score:= - ThinkingHH.Health |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
200 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
201 |
// rate explosion |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
202 |
for i:= 0 to Targets.Count do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
203 |
with Targets.ar[i] do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
204 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
205 |
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
|
206 |
if dmg > 0 then |
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:= dmg shr 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
209 |
if dmg > abs(Score) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
210 |
if Score > 0 then inc(Result, KillScore) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
211 |
else dec(Result, KillScore * 3) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
212 |
else |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
213 |
if Score > 0 then inc(Result, dmg) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
214 |
else dec(Result, dmg * 3) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
215 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
216 |
end; |
70 | 217 |
Result:= Result * 1024 |
66
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 |
|
79 | 220 |
function RateShove(Me: PGear; x, y, r, power: integer): integer; |
221 |
var i, dmg: integer; |
|
222 |
begin |
|
223 |
Result:= 0; |
|
224 |
for i:= 0 to Targets.Count do |
|
225 |
with Targets.ar[i] do |
|
226 |
begin |
|
227 |
dmg:= r - Round(sqrt(sqr(Point.x - x) + sqr(Point.y - y))); |
|
228 |
if dmg > 0 then |
|
229 |
begin |
|
230 |
if power > abs(Score) then |
|
231 |
if Score > 0 then inc(Result, KillScore) |
|
232 |
else dec(Result, KillScore * 3) |
|
233 |
else |
|
234 |
if Score > 0 then inc(Result, power) |
|
235 |
else dec(Result, power * 3) |
|
236 |
end; |
|
237 |
end; |
|
238 |
Result:= Result * 1024 |
|
239 |
end; |
|
240 |
||
75 | 241 |
function HHGo(Gear: PGear; out GoInfo: TGoInfo): boolean; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
242 |
var pX, pY: integer; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
243 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
244 |
Result:= false; |
75 | 245 |
GoInfo.Ticks:= 0; |
246 |
GoInfo.FallTicks:= 0; |
|
4 | 247 |
repeat |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
248 |
pX:= round(Gear.X); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
249 |
pY:= round(Gear.Y); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
250 |
if pY + cHHRadius >= cWaterLine then exit; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
251 |
if (Gear.State and gstFalling) <> 0 then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
252 |
begin |
75 | 253 |
inc(GoInfo.Ticks); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
254 |
Gear.dY:= Gear.dY + cGravity; |
75 | 255 |
if Gear.dY > 0.40 then |
256 |
begin |
|
257 |
Goinfo.FallTicks:= 0; |
|
258 |
exit |
|
259 |
end; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
260 |
Gear.Y:= Gear.Y + Gear.dY; |
75 | 261 |
if round(Gear.Y) > pY then inc(GoInfo.FallTicks); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
262 |
if TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
263 |
begin |
75 | 264 |
inc(GoInfo.Ticks, 300); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
265 |
Gear.State:= Gear.State and not (gstFalling or gstHHJumping); |
75 | 266 |
Gear.dY:= 0; |
267 |
Result:= true; |
|
268 |
exit |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
269 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
270 |
continue |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
271 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
272 |
{if ((Gear.Message and gm_LJump )<>0) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
273 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
274 |
Gear.Message:= 0; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
275 |
if not HHTestCollisionYwithGear(Gear, -1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
276 |
if not TestCollisionXwithXYShift(Gear, 0, -2, Sign(Gear.dX)) then Gear.Y:= Gear.Y - 2 else |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
277 |
if not TestCollisionXwithXYShift(Gear, 0, -1, Sign(Gear.dX)) then Gear.Y:= Gear.Y - 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
278 |
if not (TestCollisionXwithGear(Gear, Sign(Gear.dX)) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
279 |
or HHTestCollisionYwithGear(Gear, -1)) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
280 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
281 |
Gear.dY:= -0.15; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
282 |
Gear.dX:= Sign(Gear.dX) * 0.15; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
283 |
Gear.State:= Gear.State or gstFalling or gstHHJumping; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
284 |
exit |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
285 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
286 |
end;} |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
287 |
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
|
288 |
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
|
289 |
if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
290 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
291 |
if not (TestCollisionXwithXYShift(Gear, 0, -6, Sign(Gear.dX)) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
292 |
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
|
293 |
if not (TestCollisionXwithXYShift(Gear, 0, -5, Sign(Gear.dX)) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
294 |
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
|
295 |
if not (TestCollisionXwithXYShift(Gear, 0, -4, Sign(Gear.dX)) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
296 |
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
|
297 |
if not (TestCollisionXwithXYShift(Gear, 0, -3, Sign(Gear.dX)) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
298 |
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
|
299 |
if not (TestCollisionXwithXYShift(Gear, 0, -2, Sign(Gear.dX)) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
300 |
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
|
301 |
if not (TestCollisionXwithXYShift(Gear, 0, -1, Sign(Gear.dX)) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
302 |
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
|
303 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
304 |
|
75 | 305 |
if not TestCollisionXwithGear(Gear, Sign(Gear.dX)) then |
306 |
begin |
|
307 |
Gear.X:= Gear.X + Gear.dX; |
|
308 |
inc(GoInfo.Ticks, cHHStepTicks) |
|
309 |
end; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
310 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
311 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
312 |
Gear.Y:= Gear.Y + 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
313 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
314 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
315 |
Gear.Y:= Gear.Y + 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
316 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
317 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
318 |
Gear.Y:= Gear.Y + 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
319 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
320 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
321 |
Gear.Y:= Gear.Y + 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
322 |
if not TestCollisionYwithGear(Gear, 1) then |
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 |
Gear.Y:= Gear.Y + 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
325 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
326 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
327 |
Gear.Y:= Gear.Y + 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
328 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
329 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
330 |
Gear.Y:= Gear.Y - 6; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
331 |
Gear.dY:= 0; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
332 |
Gear.dX:= 0.0000001 * Sign(Gear.dX); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
333 |
Gear.State:= Gear.State or gstFalling |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
334 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
335 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
336 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
337 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
338 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
339 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
340 |
end; |
75 | 341 |
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
|
342 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
343 |
Result:= true; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
344 |
exit |
75 | 345 |
end |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
346 |
until (pX = round(Gear.X)) and (pY = round(Gear.Y)) and ((Gear.State and gstFalling) = 0); |
4 | 347 |
end; |
348 |
||
349 |
end. |