author | unc0rr |
Sat, 26 Aug 2006 09:41:33 +0000 | |
changeset 124 | 75b892eff74d |
parent 108 | 08f1fe6f21f8 |
child 136 | 89970b70b076 |
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; |
4 | 58 |
function TestColl(x, y, r: integer): boolean; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
59 |
function RateExplosion(Me: PGear; x, y, r: integer): integer; |
79 | 60 |
function RateShove(Me: PGear; x, y, r, power: integer): integer; |
80 | 61 |
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
|
62 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
63 |
var ThinkingHH: PGear; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
64 |
Targets: TTargets; |
4 | 65 |
|
66 |
implementation |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
67 |
uses uTeams, uMisc, uLand, uCollisions; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
68 |
const KillScore = 200; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
69 |
MAXBONUS = 1024; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
70 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
71 |
type TBonus = record |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
72 |
X, Y: integer; |
70 | 73 |
Radius: integer; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
74 |
Score: integer; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
75 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
76 |
var bonuses: record |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
77 |
Count: Longword; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
78 |
ar: array[0..Pred(MAXBONUS)] of TBonus; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
79 |
end; |
71 | 80 |
KnownExplosion: record |
81 |
X, Y, Radius: integer |
|
82 |
end = (X: 0; Y: 0; Radius: 0); |
|
4 | 83 |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
84 |
procedure FillTargets; |
4 | 85 |
var t: PTeam; |
64 | 86 |
i: Longword; |
4 | 87 |
begin |
88 |
Targets.Count:= 0; |
|
89 |
t:= TeamsList; |
|
90 |
while t <> nil do |
|
91 |
begin |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
92 |
for i:= 0 to cMaxHHIndex do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
93 |
if (t.Hedgehogs[i].Gear <> nil) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
94 |
and (t.Hedgehogs[i].Gear <> ThinkingHH) then |
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 |
with Targets.ar[Targets.Count], t.Hedgehogs[i] do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
97 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
98 |
Point.X:= Round(Gear.X); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
99 |
Point.Y:= Round(Gear.Y); |
74 | 100 |
if t.Color <> CurrentTeam.Color then Score:= Gear.Health |
101 |
else Score:= -Gear.Health |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
102 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
103 |
inc(Targets.Count) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
104 |
end; |
4 | 105 |
t:= t.Next |
64 | 106 |
end |
4 | 107 |
end; |
108 |
||
70 | 109 |
procedure FillBonuses(isAfterAttack: boolean); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
110 |
var Gear: PGear; |
70 | 111 |
MyColor: Longword; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
112 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
113 |
procedure AddBonus(x, y: integer; r: Longword; s: integer); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
114 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
115 |
bonuses.ar[bonuses.Count].x:= x; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
116 |
bonuses.ar[bonuses.Count].y:= y; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
117 |
bonuses.ar[bonuses.Count].Radius:= r; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
118 |
bonuses.ar[bonuses.Count].Score:= s; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
119 |
inc(bonuses.Count); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
120 |
TryDo(bonuses.Count <= MAXBONUS, 'Bonuses overflow', true) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
121 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
122 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
123 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
124 |
bonuses.Count:= 0; |
70 | 125 |
MyColor:= PHedgehog(ThinkingHH.Hedgehog).Team.Color; |
95 | 126 |
SDL_LockMutex(GearsListMutex); |
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; |
95 | 144 |
SDL_UnlockMutex(GearsListMutex); |
71 | 145 |
if isAfterAttack and (KnownExplosion.Radius > 0) then |
146 |
with KnownExplosion do |
|
74 | 147 |
AddBonus(X, Y, Radius + 10, -Radius); |
71 | 148 |
end; |
149 |
||
150 |
procedure AwareOfExplosion(x, y, r: integer); |
|
151 |
begin |
|
152 |
KnownExplosion.X:= x; |
|
153 |
KnownExplosion.Y:= y; |
|
154 |
KnownExplosion.Radius:= r |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
155 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
156 |
|
70 | 157 |
function RatePlace(Gear: PGear): integer; |
158 |
var i, r: integer; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
159 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
160 |
Result:= 0; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
161 |
for i:= 0 to Pred(bonuses.Count) do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
162 |
with bonuses.ar[i] do |
70 | 163 |
begin |
164 |
r:= round(sqrt(sqr(Gear.X - X) + sqr(Gear.Y - y))); |
|
165 |
if r < Radius then |
|
166 |
inc(Result, Score * (Radius - r)) |
|
167 |
end; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
168 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
169 |
|
4 | 170 |
function TestColl(x, y, r: integer): boolean; |
171 |
begin |
|
172 |
Result:=(((x-r) and $FFFFF800) = 0)and(((y-r) and $FFFFFC00) = 0) and (Land[y-r, x-r] <> 0); |
|
173 |
if Result then exit; |
|
174 |
Result:=(((x-r) and $FFFFF800) = 0)and(((y+r) and $FFFFFC00) = 0) and (Land[y+r, x-r] <> 0); |
|
175 |
if Result then exit; |
|
176 |
Result:=(((x+r) and $FFFFF800) = 0)and(((y-r) and $FFFFFC00) = 0) and (Land[y-r, x+r] <> 0); |
|
177 |
if Result then exit; |
|
178 |
Result:=(((x+r) and $FFFFF800) = 0)and(((y+r) and $FFFFFC00) = 0) and (Land[y+r, x+r] <> 0); |
|
179 |
end; |
|
180 |
||
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
181 |
function RateExplosion(Me: PGear; x, y, r: integer): integer; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
182 |
var i, dmg: integer; |
4 | 183 |
begin |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
184 |
Result:= 0; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
185 |
// add our virtual position |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
186 |
with Targets.ar[Targets.Count] do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
187 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
188 |
Point.x:= round(Me.X); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
189 |
Point.y:= round(Me.Y); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
190 |
Score:= - ThinkingHH.Health |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
191 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
192 |
// rate explosion |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
193 |
for i:= 0 to Targets.Count do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
194 |
with Targets.ar[i] do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
195 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
196 |
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
|
197 |
if dmg > 0 then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
198 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
199 |
dmg:= dmg shr 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
200 |
if dmg > abs(Score) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
201 |
if Score > 0 then inc(Result, KillScore) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
202 |
else dec(Result, KillScore * 3) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
203 |
else |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
204 |
if Score > 0 then inc(Result, dmg) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
205 |
else dec(Result, dmg * 3) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
206 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
207 |
end; |
70 | 208 |
Result:= Result * 1024 |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
209 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
210 |
|
79 | 211 |
function RateShove(Me: PGear; x, y, r, power: integer): integer; |
212 |
var i, dmg: integer; |
|
213 |
begin |
|
214 |
Result:= 0; |
|
215 |
for i:= 0 to Targets.Count do |
|
216 |
with Targets.ar[i] do |
|
217 |
begin |
|
218 |
dmg:= r - Round(sqrt(sqr(Point.x - x) + sqr(Point.y - y))); |
|
219 |
if dmg > 0 then |
|
220 |
begin |
|
221 |
if power > abs(Score) then |
|
222 |
if Score > 0 then inc(Result, KillScore) |
|
223 |
else dec(Result, KillScore * 3) |
|
224 |
else |
|
225 |
if Score > 0 then inc(Result, power) |
|
226 |
else dec(Result, power * 3) |
|
227 |
end; |
|
228 |
end; |
|
229 |
Result:= Result * 1024 |
|
230 |
end; |
|
231 |
||
80 | 232 |
function HHJump(Gear: PGear; JumpType: TJumpType; out GoInfo: TGoInfo): boolean; |
233 |
var bX, bY: integer; |
|
234 |
begin |
|
235 |
Result:= false; |
|
236 |
GoInfo.Ticks:= 0; |
|
237 |
GoInfo.FallPix:= 0; |
|
238 |
GoInfo.JumpType:= jmpNone; |
|
239 |
bX:= round(Gear.X); |
|
240 |
bY:= round(Gear.Y); |
|
241 |
case JumpType of |
|
242 |
jmpNone: exit; |
|
243 |
jmpHJump: if not TestCollisionYwithGear(Gear, -1) then |
|
244 |
begin |
|
245 |
Gear.dY:= -0.20; |
|
108 | 246 |
Gear.dX:= 0.0000001 * hwSign(Gear.dX); |
247 |
Gear.X:= Gear.X - hwSign(Gear.dX)*0.00008; // shift compensation |
|
80 | 248 |
Gear.State:= Gear.State or gstFalling or gstHHJumping; |
249 |
end else exit; |
|
250 |
jmpLJump: begin |
|
251 |
if not TestCollisionYwithGear(Gear, -1) then |
|
108 | 252 |
if not TestCollisionXwithXYShift(Gear, 0, -2, hwSign(Gear.dX)) then Gear.Y:= Gear.Y - 2 else |
253 |
if not TestCollisionXwithXYShift(Gear, 0, -1, hwSign(Gear.dX)) then Gear.Y:= Gear.Y - 1; |
|
254 |
if not (TestCollisionXwithGear(Gear, hwSign(Gear.dX)) |
|
80 | 255 |
or TestCollisionYwithGear(Gear, -1)) then |
256 |
begin |
|
257 |
Gear.dY:= -0.15; |
|
108 | 258 |
Gear.dX:= hwSign(Gear.dX) * 0.15; |
80 | 259 |
Gear.State:= Gear.State or gstFalling or gstHHJumping |
82 | 260 |
end else exit |
80 | 261 |
end |
262 |
end; |
|
263 |
||
264 |
repeat |
|
265 |
if Gear.Y + cHHRadius >= cWaterLine then exit; |
|
266 |
if (Gear.State and gstFalling) <> 0 then |
|
267 |
begin |
|
268 |
if (GoInfo.Ticks = 350) then |
|
269 |
if (abs(Gear.dX) < 0.0000002) and (Gear.dY < -0.02) then |
|
270 |
begin |
|
271 |
Gear.dY:= -0.25; |
|
108 | 272 |
Gear.dX:= hwSign(Gear.dX) * 0.02 |
80 | 273 |
end; |
108 | 274 |
if TestCollisionXwithGear(Gear, hwSign(Gear.dX)) then Gear.dX:= 0.0000001 * hwSign(Gear.dX); |
80 | 275 |
Gear.X:= Gear.X + Gear.dX; |
276 |
inc(GoInfo.Ticks); |
|
277 |
Gear.dY:= Gear.dY + cGravity; |
|
278 |
if Gear.dY > 0.40 then exit; |
|
279 |
if (Gear.dY < 0)and TestCollisionYwithGear(Gear, -1) then Gear.dY:= 0; |
|
280 |
Gear.Y:= Gear.Y + Gear.dY; |
|
281 |
if (Gear.dY >= 0)and TestCollisionYwithGear(Gear, 1) then |
|
282 |
begin |
|
283 |
Gear.State:= Gear.State and not (gstFalling or gstHHJumping); |
|
284 |
Gear.dY:= 0; |
|
285 |
case JumpType of |
|
286 |
jmpHJump: if (bY - Gear.Y > 5) then |
|
287 |
begin |
|
288 |
Result:= true; |
|
289 |
GoInfo.JumpType:= jmpHJump; |
|
290 |
inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after |
|
291 |
end; |
|
292 |
jmpLJump: if abs(bX - Gear.X) > 30 then |
|
293 |
begin |
|
294 |
Result:= true; |
|
295 |
GoInfo.JumpType:= jmpLJump; |
|
296 |
inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after |
|
297 |
end; |
|
298 |
end; |
|
299 |
exit |
|
300 |
end; |
|
301 |
end; |
|
302 |
until false; |
|
303 |
end; |
|
304 |
||
305 |
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
|
306 |
var pX, pY: integer; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
307 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
308 |
Result:= false; |
80 | 309 |
AltGear^:= Gear^; |
310 |
||
75 | 311 |
GoInfo.Ticks:= 0; |
80 | 312 |
GoInfo.FallPix:= 0; |
313 |
GoInfo.JumpType:= jmpNone; |
|
4 | 314 |
repeat |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
315 |
pX:= round(Gear.X); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
316 |
pY:= round(Gear.Y); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
317 |
if pY + cHHRadius >= cWaterLine then exit; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
318 |
if (Gear.State and gstFalling) <> 0 then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
319 |
begin |
75 | 320 |
inc(GoInfo.Ticks); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
321 |
Gear.dY:= Gear.dY + cGravity; |
75 | 322 |
if Gear.dY > 0.40 then |
323 |
begin |
|
80 | 324 |
Goinfo.FallPix:= 0; |
82 | 325 |
HHJump(AltGear, jmpLJump, GoInfo); // try ljump enstead of fall with damage |
75 | 326 |
exit |
327 |
end; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
328 |
Gear.Y:= Gear.Y + Gear.dY; |
80 | 329 |
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
|
330 |
if TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
331 |
begin |
75 | 332 |
inc(GoInfo.Ticks, 300); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
333 |
Gear.State:= Gear.State and not (gstFalling or gstHHJumping); |
75 | 334 |
Gear.dY:= 0; |
335 |
Result:= true; |
|
82 | 336 |
HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall |
75 | 337 |
exit |
66
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 |
continue |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
340 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
341 |
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
|
342 |
if (Gear.Message and gm_Right )<>0 then Gear.dX:= 1.0 else exit; |
108 | 343 |
if TestCollisionXwithGear(Gear, hwSign(Gear.dX)) then |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
344 |
begin |
108 | 345 |
if not (TestCollisionXwithXYShift(Gear, 0, -6, hwSign(Gear.dX)) |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
346 |
or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1; |
108 | 347 |
if not (TestCollisionXwithXYShift(Gear, 0, -5, hwSign(Gear.dX)) |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
348 |
or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1; |
108 | 349 |
if not (TestCollisionXwithXYShift(Gear, 0, -4, hwSign(Gear.dX)) |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
350 |
or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1; |
108 | 351 |
if not (TestCollisionXwithXYShift(Gear, 0, -3, hwSign(Gear.dX)) |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
352 |
or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1; |
108 | 353 |
if not (TestCollisionXwithXYShift(Gear, 0, -2, hwSign(Gear.dX)) |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
354 |
or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1; |
108 | 355 |
if not (TestCollisionXwithXYShift(Gear, 0, -1, hwSign(Gear.dX)) |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
356 |
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
|
357 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
358 |
|
108 | 359 |
if not TestCollisionXwithGear(Gear, hwSign(Gear.dX)) then |
75 | 360 |
begin |
361 |
Gear.X:= Gear.X + Gear.dX; |
|
362 |
inc(GoInfo.Ticks, cHHStepTicks) |
|
363 |
end; |
|
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 |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
366 |
Gear.Y:= Gear.Y + 1; |
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 |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
369 |
Gear.Y:= Gear.Y + 1; |
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 |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
372 |
Gear.Y:= Gear.Y + 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
373 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
374 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
375 |
Gear.Y:= Gear.Y + 1; |
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 - 6; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
385 |
Gear.dY:= 0; |
108 | 386 |
Gear.dX:= 0.0000001 * hwSign(Gear.dX); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
387 |
Gear.State:= Gear.State or gstFalling |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
388 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
389 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
390 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
391 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
392 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
393 |
end |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
394 |
end; |
75 | 395 |
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
|
396 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
397 |
Result:= true; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
398 |
exit |
75 | 399 |
end |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
400 |
until (pX = round(Gear.X)) and (pY = round(Gear.Y)) and ((Gear.State and gstFalling) = 0); |
80 | 401 |
HHJump(AltGear, jmpHJump, GoInfo) |
4 | 402 |
end; |
403 |
||
404 |
end. |