author | displacer |
Sun, 03 Jun 2007 22:19:47 +0000 | |
changeset 535 | a14eaf35cf4b |
parent 534 | 92fb2b0d5117 |
child 543 | 465e2ec8f05f |
permissions | -rw-r--r-- |
71 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
393 | 3 |
* Copyright (c) 2005-2007 Andrey Korotaev <unC0Rr@gmail.com> |
71 | 4 |
* |
183 | 5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
71 | 8 |
* |
183 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
71 | 13 |
* |
183 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
71 | 17 |
*) |
18 |
||
4 | 19 |
unit uAIAmmoTests; |
20 |
interface |
|
351 | 21 |
uses SDLh, uGears, uConsts, uFloat; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
22 |
|
371 | 23 |
function TestBazooka(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
374 | 24 |
function TestGrenade(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
375 | 25 |
function TestShotgun(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
438 | 26 |
function TestDesertEagle(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
371 | 27 |
function TestBaseballBat(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
28 |
function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
|
433 | 29 |
|
371 | 30 |
type TAmmoTestProc = function (Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
31 |
const AmmoTests: array[TAmmoType] of TAmmoTestProc = |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
32 |
( |
374 | 33 |
{amGrenade} @TestGrenade, |
78 | 34 |
{amClusterBomb} nil, |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
35 |
{amBazooka} @TestBazooka, |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
36 |
{amUFO} nil, |
438 | 37 |
{amShotgun} @TestShotgun, |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
38 |
{amPickHammer} nil, |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
39 |
{amSkip} nil, |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
40 |
{amRope} nil, |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
41 |
{amMine} nil, |
438 | 42 |
{amDEagle} @TestDesertEagle, |
79 | 43 |
{amDynamite} nil, |
433 | 44 |
{amFirePunch} @TestFirePunch, |
45 |
{amBaseballBat} @TestBaseballBat, |
|
263 | 46 |
{amParachute} nil, |
285 | 47 |
{amAirAttack} nil, |
302 | 48 |
{amMineStrike} nil, |
409 | 49 |
{amBlowTorch} nil, |
520 | 50 |
{amGirder} nil, |
534 | 51 |
{amTeleport} nil, |
52 |
{amSwitch} nil |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
53 |
); |
4 | 54 |
|
439 | 55 |
const BadTurn = Low(LongInt) div 4; |
369 | 56 |
|
143 | 57 |
|
4 | 58 |
implementation |
75 | 59 |
uses uMisc, uAIMisc, uLand; |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
60 |
|
371 | 61 |
function Metric(x1, y1, x2, y2: LongInt): LongInt; |
4 | 62 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
63 |
Metric:= abs(x1 - x2) + abs(y1 - y2) |
4 | 64 |
end; |
65 |
||
371 | 66 |
function TestBazooka(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
351 | 67 |
var Vx, Vy, r: hwFloat; |
498 | 68 |
rTime: LongInt; |
371 | 69 |
Score, EX, EY: LongInt; |
70 |
Result: LongInt; |
|
4 | 71 |
|
371 | 72 |
function CheckTrace: LongInt; |
351 | 73 |
var x, y, dX, dY: hwFloat; |
371 | 74 |
t: LongInt; |
75 |
Result: LongInt; |
|
4 | 76 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
77 |
x:= Me^.X; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
78 |
y:= Me^.Y; |
4 | 79 |
dX:= Vx; |
80 |
dY:= -Vy; |
|
498 | 81 |
t:= rTime; |
4 | 82 |
repeat |
83 |
x:= x + dX; |
|
84 |
y:= y + dY; |
|
85 |
dX:= dX + cWindSpeed; |
|
86 |
dY:= dY + cGravity; |
|
87 |
dec(t) |
|
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
88 |
until TestColl(hwRound(x), hwRound(y), 5) or (t <= 0); |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
89 |
EX:= hwRound(x); |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
90 |
EY:= hwRound(y); |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
91 |
Result:= RateExplosion(Me, EX, EY, 101); |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
92 |
if Result = 0 then Result:= - Metric(Targ.X, Targ.Y, EX, EY) div 64; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
93 |
CheckTrace:= Result |
4 | 94 |
end; |
95 |
||
96 |
begin |
|
97 |
Time:= 0; |
|
375 | 98 |
rTime:= 350; |
71 | 99 |
ExplR:= 0; |
70 | 100 |
Result:= BadTurn; |
4 | 101 |
repeat |
375 | 102 |
rTime:= rTime + 300 + Level * 50 + random(300); |
498 | 103 |
Vx:= - cWindSpeed * rTime * _0_5 + (int2hwFloat(Targ.X) - Me^.X) / int2hwFloat(rTime); |
104 |
Vy:= cGravity * rTime * _0_5 - (int2hwFloat(Targ.Y) - Me^.Y) / int2hwFloat(rTime); |
|
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
105 |
r:= Distance(Vx, Vy); |
498 | 106 |
if not (r > _1) then |
4 | 107 |
begin |
64 | 108 |
Score:= CheckTrace; |
109 |
if Result <= Score then |
|
110 |
begin |
|
439 | 111 |
Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random((Level - 1) * 9)); |
433 | 112 |
Power:= hwRound(r * cMaxPower) - random((Level - 1) * 17 + 1); |
74 | 113 |
ExplR:= 100; |
71 | 114 |
ExplX:= EX; |
115 |
ExplY:= EY; |
|
143 | 116 |
Result:= Score |
64 | 117 |
end; |
4 | 118 |
end |
375 | 119 |
until (rTime > 4250); |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
369
diff
changeset
|
120 |
TestBazooka:= Result |
39 | 121 |
end; |
374 | 122 |
|
371 | 123 |
function TestGrenade(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
70 | 124 |
const tDelta = 24; |
351 | 125 |
var Vx, Vy, r: hwFloat; |
374 | 126 |
Score, EX, EY, Result: LongInt; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
127 |
TestTime: Longword; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
128 |
|
371 | 129 |
function CheckTrace: LongInt; |
351 | 130 |
var x, y, dY: hwFloat; |
371 | 131 |
t: LongInt; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
132 |
begin |
374 | 133 |
x:= Me^.X; |
134 |
y:= Me^.Y; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
135 |
dY:= -Vy; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
136 |
t:= TestTime; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
137 |
repeat |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
138 |
x:= x + Vx; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
139 |
y:= y + dY; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
140 |
dY:= dY + cGravity; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
141 |
dec(t) |
374 | 142 |
until TestColl(hwRound(x), hwRound(y), 5) or (t = 0); |
143 |
EX:= hwRound(x); |
|
144 |
EY:= hwRound(y); |
|
145 |
if t < 50 then CheckTrace:= RateExplosion(Me, EX, EY, 101) |
|
146 |
else CheckTrace:= Low(LongInt) |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
147 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
148 |
|
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
149 |
begin |
70 | 150 |
Result:= BadTurn; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
151 |
TestTime:= 0; |
71 | 152 |
ExplR:= 0; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
153 |
repeat |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
154 |
inc(TestTime, 1000); |
498 | 155 |
Vx:= (int2hwFloat(Targ.X) - Me^.X) / int2hwFloat(TestTime + tDelta); |
156 |
Vy:= cGravity * ((TestTime + tDelta) div 2) - (int2hwFloat(Targ.Y) - Me^.Y) / int2hwFloat(TestTime + tDelta); |
|
374 | 157 |
r:= Distance(Vx, Vy); |
498 | 158 |
if not (r > _1) then |
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 |
Score:= CheckTrace; |
70 | 161 |
if Result < Score then |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
162 |
begin |
374 | 163 |
Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random(Level)); |
433 | 164 |
Power:= hwRound(r * cMaxPower) + AIrndSign(random(Level) * 15); |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
165 |
Time:= TestTime; |
74 | 166 |
ExplR:= 100; |
71 | 167 |
ExplX:= EX; |
168 |
ExplY:= EY; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
169 |
Result:= Score |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
170 |
end; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
171 |
end |
439 | 172 |
until (TestTime = 4000); |
374 | 173 |
TestGrenade:= Result |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
64
diff
changeset
|
174 |
end; |
375 | 175 |
|
371 | 176 |
function TestShotgun(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
351 | 177 |
var Vx, Vy, x, y: hwFloat; |
375 | 178 |
rx, ry, Result: LongInt; |
179 |
begin |
|
79 | 180 |
ExplR:= 0; |
70 | 181 |
Time:= 0; |
182 |
Power:= 1; |
|
439 | 183 |
if Metric(hwRound(Me^.X), hwRound(Me^.Y), Targ.X, Targ.Y) < 80 then |
184 |
exit(BadTurn); |
|
498 | 185 |
Vx:= (int2hwFloat(Targ.X) - Me^.X) * _1div1024; |
186 |
Vy:= (int2hwFloat(Targ.Y) - Me^.Y) * _1div1024; |
|
375 | 187 |
x:= Me^.X; |
188 |
y:= Me^.Y; |
|
70 | 189 |
Angle:= DxDy2AttackAngle(Vx, -Vy); |
190 |
repeat |
|
191 |
x:= x + vX; |
|
192 |
y:= y + vY; |
|
375 | 193 |
rx:= hwRound(x); |
194 |
ry:= hwRound(y); |
|
195 |
if TestColl(rx, ry, 2) then |
|
70 | 196 |
begin |
509 | 197 |
x:= x + vX * 8; |
198 |
y:= y + vY * 8; |
|
199 |
Result:= RateShotgun(Me, rx, ry) * 2; |
|
375 | 200 |
if Result = 0 then Result:= - Metric(Targ.X, Targ.Y, rx, ry) div 64 |
143 | 201 |
else dec(Result, Level * 4000); |
375 | 202 |
exit(Result) |
70 | 203 |
end |
498 | 204 |
until (Abs(Targ.X - hwRound(x)) + Abs(Targ.Y - hwRound(y)) < 4) or (x < _0) or (y < _0) or (x > _2048) or (y > _1024); |
375 | 205 |
TestShotgun:= BadTurn |
70 | 206 |
end; |
438 | 207 |
|
371 | 208 |
function TestDesertEagle(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
351 | 209 |
var Vx, Vy, x, y, t: hwFloat; |
75 | 210 |
d: Longword; |
438 | 211 |
Result: LongInt; |
75 | 212 |
begin |
79 | 213 |
ExplR:= 0; |
75 | 214 |
Time:= 0; |
215 |
Power:= 1; |
|
498 | 216 |
if Abs(hwRound(Me^.X) - Targ.X) + Abs(hwRound(Me^.Y) - Targ.Y) < 80 then |
439 | 217 |
exit(BadTurn); |
498 | 218 |
t:= _0_5 / Distance(int2hwFloat(Targ.X) - Me^.X, int2hwFloat(Targ.Y) - Me^.Y); |
219 |
Vx:= (int2hwFloat(Targ.X) - Me^.X) * t; |
|
220 |
Vy:= (int2hwFloat(Targ.Y) - Me^.Y) * t; |
|
438 | 221 |
x:= Me^.X; |
222 |
y:= Me^.Y; |
|
75 | 223 |
Angle:= DxDy2AttackAngle(Vx, -Vy); |
224 |
d:= 0; |
|
225 |
repeat |
|
226 |
x:= x + vX; |
|
227 |
y:= y + vY; |
|
438 | 228 |
if ((hwRound(x) and $FFFFF800) = 0)and((hwRound(y) and $FFFFFC00) = 0) |
229 |
and (Land[hwRound(y), hwRound(x)] <> 0) then inc(d); |
|
498 | 230 |
until (Abs(Targ.X - hwRound(x)) + Abs(Targ.Y - hwRound(y)) < 4) or (x < _0) or (y < _0) or (x > _2048) or (y > _1024) or (d > 200); |
231 |
if Abs(Targ.X - hwRound(x)) + Abs(Targ.Y - hwRound(y)) < 3 then Result:= max(0, (4 - d div 50) * 7 * 1024) |
|
232 |
else Result:= Low(LongInt); |
|
438 | 233 |
TestDesertEagle:= Result |
75 | 234 |
end; |
438 | 235 |
|
371 | 236 |
function TestBaseballBat(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
433 | 237 |
var Result: LongInt; |
79 | 238 |
begin |
239 |
ExplR:= 0; |
|
498 | 240 |
if (Level > 2) and not (Abs(hwRound(Me^.X) - Targ.X) + Abs(hwRound(Me^.Y) - Targ.Y) < 25) then |
433 | 241 |
exit(BadTurn); |
242 |
||
79 | 243 |
Time:= 0; |
244 |
Power:= 1; |
|
498 | 245 |
if (Targ.X) - hwRound(Me^.X) >= 0 then Angle:= cMaxAngle div 4 |
246 |
else Angle:= - cMaxAngle div 4; |
|
247 |
Result:= RateShove(Me, hwRound(Me^.X) + 10 * hwSign(int2hwFloat(Targ.X) - Me^.X), hwRound(Me^.Y), 15, 30); |
|
433 | 248 |
if Result <= 0 then Result:= BadTurn else inc(Result); |
249 |
TestBaseballBat:= Result |
|
79 | 250 |
end; |
251 |
||
371 | 252 |
function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
433 | 253 |
var i, Result: LongInt; |
82 | 254 |
begin |
255 |
ExplR:= 0; |
|
256 |
Time:= 0; |
|
257 |
Power:= 1; |
|
433 | 258 |
Angle:= 0; |
498 | 259 |
if (Abs(hwRound(Me^.X) - Targ.X) > 25) or (Abs(hwRound(Me^.Y) - 50 - Targ.Y) > 50) then |
433 | 260 |
exit(BadTurn); |
261 |
||
82 | 262 |
Result:= 0; |
263 |
for i:= 0 to 4 do |
|
498 | 264 |
Result:= Result + RateShove(Me, hwRound(Me^.X) + 10 * hwSign(int2hwFloat(Targ.X) - Me^.X), |
265 |
hwRound(Me^.Y) - 20 * i - 5, 10, 30); |
|
434 | 266 |
if Result <= 0 then Result:= BadTurn else inc(Result); |
433 | 267 |
TestFirePunch:= Result |
82 | 268 |
end; |
433 | 269 |
|
4 | 270 |
end. |