author | displacer |
Sun, 01 Oct 2006 20:31:48 +0000 | |
changeset 179 | 06e472d3f9f8 |
parent 136 | 89970b70b076 |
child 183 | 57c2ef19f719 |
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; |
136 | 62 |
function rndSign(num: integer): integer; |
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; |
95 | 127 |
SDL_LockMutex(GearsListMutex); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
128 |
Gear:= GearsList; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
129 |
while Gear <> nil do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
130 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
131 |
case Gear.Kind of |
70 | 132 |
gtCase: AddBonus(round(Gear.X), round(Gear.Y), 33, 25); |
74 | 133 |
gtMine: if (Gear.State and gstAttacking) = 0 then AddBonus(round(Gear.X), round(Gear.Y), 50, -50) |
134 |
else AddBonus(round(Gear.X), round(Gear.Y), 100, -50); // mine is on |
|
70 | 135 |
gtDynamite: AddBonus(round(Gear.X), round(Gear.Y), 150, -75); |
136 |
gtHedgehog: begin |
|
74 | 137 |
if Gear.Damage >= Gear.Health then AddBonus(round(Gear.X), round(Gear.Y), 60, -25) else |
138 |
if isAfterAttack and (ThinkingHH.Hedgehog <> Gear.Hedgehog) then |
|
139 |
if (MyColor = PHedgehog(Gear.Hedgehog).Team.Color) then AddBonus(round(Gear.X), round(Gear.Y), 150, -3) // hedgehog-friend |
|
140 |
else AddBonus(round(Gear.X), round(Gear.Y), 100, 3) |
|
70 | 141 |
end; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
142 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
143 |
Gear:= Gear.NextGear |
71 | 144 |
end; |
95 | 145 |
SDL_UnlockMutex(GearsListMutex); |
71 | 146 |
if isAfterAttack and (KnownExplosion.Radius > 0) then |
147 |
with KnownExplosion do |
|
74 | 148 |
AddBonus(X, Y, Radius + 10, -Radius); |
71 | 149 |
end; |
150 |
||
151 |
procedure AwareOfExplosion(x, y, r: integer); |
|
152 |
begin |
|
153 |
KnownExplosion.X:= x; |
|
154 |
KnownExplosion.Y:= y; |
|
155 |
KnownExplosion.Radius:= r |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
156 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
157 |
|
70 | 158 |
function RatePlace(Gear: PGear): integer; |
159 |
var i, r: integer; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
160 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
161 |
Result:= 0; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
162 |
for i:= 0 to Pred(bonuses.Count) do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
163 |
with bonuses.ar[i] do |
70 | 164 |
begin |
165 |
r:= round(sqrt(sqr(Gear.X - X) + sqr(Gear.Y - y))); |
|
166 |
if r < Radius then |
|
167 |
inc(Result, Score * (Radius - r)) |
|
168 |
end; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
169 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
170 |
|
4 | 171 |
function TestColl(x, y, r: integer): boolean; |
172 |
begin |
|
173 |
Result:=(((x-r) and $FFFFF800) = 0)and(((y-r) and $FFFFFC00) = 0) and (Land[y-r, x-r] <> 0); |
|
174 |
if Result then exit; |
|
175 |
Result:=(((x-r) and $FFFFF800) = 0)and(((y+r) and $FFFFFC00) = 0) and (Land[y+r, x-r] <> 0); |
|
176 |
if Result then exit; |
|
177 |
Result:=(((x+r) and $FFFFF800) = 0)and(((y-r) and $FFFFFC00) = 0) and (Land[y-r, x+r] <> 0); |
|
178 |
if Result then exit; |
|
179 |
Result:=(((x+r) and $FFFFF800) = 0)and(((y+r) and $FFFFFC00) = 0) and (Land[y+r, x+r] <> 0); |
|
180 |
end; |
|
181 |
||
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
182 |
function RateExplosion(Me: PGear; x, y, r: integer): integer; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
183 |
var i, dmg: integer; |
4 | 184 |
begin |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
185 |
Result:= 0; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
186 |
// add our virtual position |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
187 |
with Targets.ar[Targets.Count] do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
188 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
189 |
Point.x:= round(Me.X); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
190 |
Point.y:= round(Me.Y); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
191 |
Score:= - ThinkingHH.Health |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
192 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
193 |
// rate explosion |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
194 |
for i:= 0 to Targets.Count do |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
195 |
with Targets.ar[i] 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 |
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
|
198 |
if dmg > 0 then |
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 |
dmg:= dmg shr 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
201 |
if dmg > abs(Score) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
202 |
if Score > 0 then inc(Result, KillScore) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
203 |
else dec(Result, KillScore * 3) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
204 |
else |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
205 |
if Score > 0 then inc(Result, dmg) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
206 |
else dec(Result, dmg * 3) |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
207 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
208 |
end; |
70 | 209 |
Result:= Result * 1024 |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
210 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
211 |
|
79 | 212 |
function RateShove(Me: PGear; x, y, r, power: integer): integer; |
213 |
var i, dmg: integer; |
|
214 |
begin |
|
215 |
Result:= 0; |
|
216 |
for i:= 0 to Targets.Count do |
|
217 |
with Targets.ar[i] do |
|
218 |
begin |
|
219 |
dmg:= r - Round(sqrt(sqr(Point.x - x) + sqr(Point.y - y))); |
|
220 |
if dmg > 0 then |
|
221 |
begin |
|
222 |
if power > abs(Score) then |
|
223 |
if Score > 0 then inc(Result, KillScore) |
|
224 |
else dec(Result, KillScore * 3) |
|
225 |
else |
|
226 |
if Score > 0 then inc(Result, power) |
|
227 |
else dec(Result, power * 3) |
|
228 |
end; |
|
229 |
end; |
|
230 |
Result:= Result * 1024 |
|
231 |
end; |
|
232 |
||
80 | 233 |
function HHJump(Gear: PGear; JumpType: TJumpType; out GoInfo: TGoInfo): boolean; |
234 |
var bX, bY: integer; |
|
235 |
begin |
|
236 |
Result:= false; |
|
237 |
GoInfo.Ticks:= 0; |
|
238 |
GoInfo.FallPix:= 0; |
|
239 |
GoInfo.JumpType:= jmpNone; |
|
240 |
bX:= round(Gear.X); |
|
241 |
bY:= round(Gear.Y); |
|
242 |
case JumpType of |
|
243 |
jmpNone: exit; |
|
244 |
jmpHJump: if not TestCollisionYwithGear(Gear, -1) then |
|
245 |
begin |
|
246 |
Gear.dY:= -0.20; |
|
108 | 247 |
Gear.dX:= 0.0000001 * hwSign(Gear.dX); |
248 |
Gear.X:= Gear.X - hwSign(Gear.dX)*0.00008; // shift compensation |
|
80 | 249 |
Gear.State:= Gear.State or gstFalling or gstHHJumping; |
250 |
end else exit; |
|
251 |
jmpLJump: begin |
|
252 |
if not TestCollisionYwithGear(Gear, -1) then |
|
108 | 253 |
if not TestCollisionXwithXYShift(Gear, 0, -2, hwSign(Gear.dX)) then Gear.Y:= Gear.Y - 2 else |
254 |
if not TestCollisionXwithXYShift(Gear, 0, -1, hwSign(Gear.dX)) then Gear.Y:= Gear.Y - 1; |
|
255 |
if not (TestCollisionXwithGear(Gear, hwSign(Gear.dX)) |
|
80 | 256 |
or TestCollisionYwithGear(Gear, -1)) then |
257 |
begin |
|
258 |
Gear.dY:= -0.15; |
|
108 | 259 |
Gear.dX:= hwSign(Gear.dX) * 0.15; |
80 | 260 |
Gear.State:= Gear.State or gstFalling or gstHHJumping |
82 | 261 |
end else exit |
80 | 262 |
end |
263 |
end; |
|
264 |
||
265 |
repeat |
|
266 |
if Gear.Y + cHHRadius >= cWaterLine then exit; |
|
267 |
if (Gear.State and gstFalling) <> 0 then |
|
268 |
begin |
|
269 |
if (GoInfo.Ticks = 350) then |
|
270 |
if (abs(Gear.dX) < 0.0000002) and (Gear.dY < -0.02) then |
|
271 |
begin |
|
272 |
Gear.dY:= -0.25; |
|
108 | 273 |
Gear.dX:= hwSign(Gear.dX) * 0.02 |
80 | 274 |
end; |
108 | 275 |
if TestCollisionXwithGear(Gear, hwSign(Gear.dX)) then Gear.dX:= 0.0000001 * hwSign(Gear.dX); |
80 | 276 |
Gear.X:= Gear.X + Gear.dX; |
277 |
inc(GoInfo.Ticks); |
|
278 |
Gear.dY:= Gear.dY + cGravity; |
|
279 |
if Gear.dY > 0.40 then exit; |
|
280 |
if (Gear.dY < 0)and TestCollisionYwithGear(Gear, -1) then Gear.dY:= 0; |
|
281 |
Gear.Y:= Gear.Y + Gear.dY; |
|
282 |
if (Gear.dY >= 0)and TestCollisionYwithGear(Gear, 1) then |
|
283 |
begin |
|
284 |
Gear.State:= Gear.State and not (gstFalling or gstHHJumping); |
|
285 |
Gear.dY:= 0; |
|
286 |
case JumpType of |
|
287 |
jmpHJump: if (bY - Gear.Y > 5) then |
|
288 |
begin |
|
289 |
Result:= true; |
|
290 |
GoInfo.JumpType:= jmpHJump; |
|
291 |
inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after |
|
292 |
end; |
|
293 |
jmpLJump: if abs(bX - Gear.X) > 30 then |
|
294 |
begin |
|
295 |
Result:= true; |
|
296 |
GoInfo.JumpType:= jmpLJump; |
|
297 |
inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after |
|
298 |
end; |
|
299 |
end; |
|
300 |
exit |
|
301 |
end; |
|
302 |
end; |
|
303 |
until false; |
|
304 |
end; |
|
305 |
||
306 |
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
|
307 |
var pX, pY: integer; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
308 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
309 |
Result:= false; |
80 | 310 |
AltGear^:= Gear^; |
311 |
||
75 | 312 |
GoInfo.Ticks:= 0; |
80 | 313 |
GoInfo.FallPix:= 0; |
314 |
GoInfo.JumpType:= jmpNone; |
|
4 | 315 |
repeat |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
316 |
pX:= round(Gear.X); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
317 |
pY:= round(Gear.Y); |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
318 |
if pY + cHHRadius >= cWaterLine then exit; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
319 |
if (Gear.State and gstFalling) <> 0 then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
320 |
begin |
75 | 321 |
inc(GoInfo.Ticks); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
322 |
Gear.dY:= Gear.dY + cGravity; |
75 | 323 |
if Gear.dY > 0.40 then |
324 |
begin |
|
80 | 325 |
Goinfo.FallPix:= 0; |
82 | 326 |
HHJump(AltGear, jmpLJump, GoInfo); // try ljump enstead of fall with damage |
75 | 327 |
exit |
328 |
end; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
329 |
Gear.Y:= Gear.Y + Gear.dY; |
80 | 330 |
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
|
331 |
if TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
332 |
begin |
75 | 333 |
inc(GoInfo.Ticks, 300); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
334 |
Gear.State:= Gear.State and not (gstFalling or gstHHJumping); |
75 | 335 |
Gear.dY:= 0; |
336 |
Result:= true; |
|
82 | 337 |
HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall |
75 | 338 |
exit |
66
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 |
continue |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
341 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
342 |
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
|
343 |
if (Gear.Message and gm_Right )<>0 then Gear.dX:= 1.0 else exit; |
108 | 344 |
if TestCollisionXwithGear(Gear, hwSign(Gear.dX)) then |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
345 |
begin |
108 | 346 |
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
|
347 |
or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1; |
108 | 348 |
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
|
349 |
or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1; |
108 | 350 |
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
|
351 |
or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1; |
108 | 352 |
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
|
353 |
or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1; |
108 | 354 |
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
|
355 |
or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1; |
108 | 356 |
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
|
357 |
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
|
358 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
359 |
|
108 | 360 |
if not TestCollisionXwithGear(Gear, hwSign(Gear.dX)) then |
75 | 361 |
begin |
362 |
Gear.X:= Gear.X + Gear.dX; |
|
363 |
inc(GoInfo.Ticks, cHHStepTicks) |
|
364 |
end; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
365 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
366 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
367 |
Gear.Y:= Gear.Y + 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
368 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
369 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
370 |
Gear.Y:= Gear.Y + 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
371 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
372 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
373 |
Gear.Y:= Gear.Y + 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
374 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
375 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
376 |
Gear.Y:= Gear.Y + 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
377 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
378 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
379 |
Gear.Y:= Gear.Y + 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
380 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
381 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
382 |
Gear.Y:= Gear.Y + 1; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
383 |
if not TestCollisionYwithGear(Gear, 1) then |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
384 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
385 |
Gear.Y:= Gear.Y - 6; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
386 |
Gear.dY:= 0; |
108 | 387 |
Gear.dX:= 0.0000001 * hwSign(Gear.dX); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
388 |
Gear.State:= Gear.State or gstFalling |
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 |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
395 |
end; |
75 | 396 |
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
|
397 |
begin |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
398 |
Result:= true; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
399 |
exit |
75 | 400 |
end |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
401 |
until (pX = round(Gear.X)) and (pY = round(Gear.Y)) and ((Gear.State and gstFalling) = 0); |
80 | 402 |
HHJump(AltGear, jmpHJump, GoInfo) |
4 | 403 |
end; |
404 |
||
136 | 405 |
function rndSign(num: integer): integer; |
406 |
begin |
|
407 |
if random(2) = 0 then Result:= num |
|
408 |
else Result:= - num |
|
409 |
end; |
|
410 |
||
4 | 411 |
end. |