18 |
18 |
19 {$INCLUDE "options.inc"} |
19 {$INCLUDE "options.inc"} |
20 |
20 |
21 unit uAIAmmoTests; |
21 unit uAIAmmoTests; |
22 interface |
22 interface |
23 uses SDLh, uGears, uConsts, uFloat; |
23 uses SDLh, uConsts, uFloat, uTypes; |
24 const amtest_OnTurn = $00000001; |
24 const amtest_OnTurn = $00000001; |
25 |
25 |
26 type TAttackParams = record |
26 type TAttackParams = record |
27 Time: Longword; |
27 Time: Longword; |
28 Angle, Power: LongInt; |
28 Angle, Power: LongInt; |
29 ExplX, ExplY, ExplR: LongInt; |
29 ExplX, ExplY, ExplR: LongInt; |
30 AttackPutX, AttackPutY: LongInt; |
30 AttackPutX, AttackPutY: LongInt; |
31 end; |
31 end; |
32 |
32 |
33 function TestBazooka(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; |
33 function TestBazooka(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; |
|
34 function TestSnowball(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; |
34 function TestGrenade(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; |
35 function TestGrenade(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; |
35 function TestMolotov(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; |
36 function TestMolotov(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; |
36 function TestClusterBomb(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; |
37 function TestClusterBomb(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; |
37 function TestWatermelon(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; |
38 function TestWatermelon(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; |
38 function TestMortar(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; |
39 function TestMortar(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; |
100 (proc: @TestShotgun; flags: 0), // amSineGun |
101 (proc: @TestShotgun; flags: 0), // amSineGun |
101 (proc: nil; flags: 0), // amFlamethrower |
102 (proc: nil; flags: 0), // amFlamethrower |
102 (proc: @TestGrenade; flags: 0), // amSMine |
103 (proc: @TestGrenade; flags: 0), // amSMine |
103 (proc: @TestFirePunch; flags: 0), // amHammer |
104 (proc: @TestFirePunch; flags: 0), // amHammer |
104 (proc: nil; flags: 0), // amResurrector |
105 (proc: nil; flags: 0), // amResurrector |
105 (proc: nil; flags: 0) // amDrillStrike |
106 (proc: nil; flags: 0),// amDrillStrike |
|
107 (proc: @TestSnowball; flags: 0) // amSnowball |
106 ); |
108 ); |
107 |
109 |
108 const BadTurn = Low(LongInt) div 4; |
110 const BadTurn = Low(LongInt) div 4; |
109 |
111 |
110 implementation |
112 implementation |
111 uses uMisc, uAIMisc, uLand; |
113 uses uAIMisc, uVariables, uUtils; |
112 |
114 |
113 function Metric(x1, y1, x2, y2: LongInt): LongInt; |
115 function Metric(x1, y1, x2, y2: LongInt): LongInt; |
114 begin |
116 begin |
115 Metric:= abs(x1 - x2) + abs(y1 - y2) |
117 Metric:= abs(x1 - x2) + abs(y1 - y2) |
116 end; |
118 end; |
168 valueResult:= Score |
170 valueResult:= Score |
169 end; |
171 end; |
170 end |
172 end |
171 until (rTime > 4250); |
173 until (rTime > 4250); |
172 TestBazooka:= valueResult |
174 TestBazooka:= valueResult |
|
175 end; |
|
176 |
|
177 function TestSnowball(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; |
|
178 var Vx, Vy, r: hwFloat; |
|
179 rTime: LongInt; |
|
180 Score, EX, EY: LongInt; |
|
181 valueResult: LongInt; |
|
182 |
|
183 function CheckTrace: LongInt; |
|
184 var x, y, dX, dY: hwFloat; |
|
185 t: LongInt; |
|
186 value: LongInt; |
|
187 begin |
|
188 x:= Me^.X; |
|
189 y:= Me^.Y; |
|
190 dX:= Vx; |
|
191 dY:= -Vy; |
|
192 t:= rTime; |
|
193 repeat |
|
194 x:= x + dX; |
|
195 y:= y + dY; |
|
196 dX:= dX + cWindSpeed; |
|
197 dY:= dY + cGravity; |
|
198 dec(t) |
|
199 until TestCollExcludingMe(Me, hwRound(x), hwRound(y), 5) or (t <= 0); |
|
200 EX:= hwRound(x); |
|
201 EY:= hwRound(y); |
|
202 value:= RateExplosion(Me, EX, EY, 5); |
|
203 if value = 0 then value:= - Metric(Targ.X, Targ.Y, EX, EY) div 64; |
|
204 CheckTrace:= value; |
|
205 end; |
|
206 |
|
207 begin |
|
208 ap.Time:= 0; |
|
209 rTime:= 350; |
|
210 ap.ExplR:= 0; |
|
211 valueResult:= BadTurn; |
|
212 repeat |
|
213 rTime:= rTime + 300 + Level * 50 + random(300); |
|
214 Vx:= - cWindSpeed * rTime * _0_5 + (int2hwFloat(Targ.X + AIrndSign(2)) - Me^.X) / int2hwFloat(rTime); |
|
215 Vy:= cGravity * rTime * _0_5 - (int2hwFloat(Targ.Y) - Me^.Y) / int2hwFloat(rTime); |
|
216 r:= Distance(Vx, Vy); |
|
217 if not (r > _1) then |
|
218 begin |
|
219 Score:= CheckTrace; |
|
220 if valueResult <= Score then |
|
221 begin |
|
222 ap.Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random((Level - 1) * 9)); |
|
223 ap.Power:= hwRound(r * cMaxPower) - random((Level - 1) * 17 + 1); |
|
224 ap.ExplR:= 100; |
|
225 ap.ExplX:= EX; |
|
226 ap.ExplY:= EY; |
|
227 valueResult:= Score |
|
228 end; |
|
229 end |
|
230 until (rTime > 4250); |
|
231 TestSnowball:= valueResult |
173 end; |
232 end; |
174 |
233 |
175 function TestMolotov(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; |
234 function TestMolotov(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; |
176 var Vx, Vy, r: hwFloat; |
235 var Vx, Vy, r: hwFloat; |
177 Score, EX, EY, valueResult: LongInt; |
236 Score, EX, EY, valueResult: LongInt; |
537 or (y.isNegative) |
596 or (y.isNegative) |
538 or (x.Round > LongWord(LAND_WIDTH)) |
597 or (x.Round > LongWord(LAND_WIDTH)) |
539 or (y.Round > LongWord(LAND_HEIGHT)) |
598 or (y.Round > LongWord(LAND_HEIGHT)) |
540 or (d > 200); |
599 or (d > 200); |
541 |
600 |
542 if Abs(Targ.X - hwRound(x)) + Abs(Targ.Y - hwRound(y)) < 3 then valueResult:= max(0, (4 - d div 50) * 7 * 1024) |
601 if Abs(Targ.X - hwRound(x)) + Abs(Targ.Y - hwRound(y)) < 3 then valueResult:= Max(0, (4 - d div 50) * 7 * 1024) |
543 else valueResult:= BadTurn; |
602 else valueResult:= BadTurn; |
544 TestDesertEagle:= valueResult |
603 TestDesertEagle:= valueResult |
545 end; |
604 end; |
546 |
605 |
547 function TestBaseballBat(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; |
606 function TestBaseballBat(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt; |