19 unit uAIAmmoTests; |
19 unit uAIAmmoTests; |
20 interface |
20 interface |
21 uses SDLh, uGears, uConsts, uFloat; |
21 uses SDLh, uGears, uConsts, uFloat; |
22 |
22 |
23 function TestBazooka(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
23 function TestBazooka(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
24 (*function TestGrenade(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
24 function TestGrenade(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
25 function TestShotgun(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
25 (*function TestShotgun(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
26 function TestDesertEagle(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
26 function TestDesertEagle(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
27 function TestBaseballBat(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
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; |
28 function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
29 *) |
29 *) |
30 type TAmmoTestProc = function (Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
30 type TAmmoTestProc = function (Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
31 const AmmoTests: array[TAmmoType] of TAmmoTestProc = |
31 const AmmoTests: array[TAmmoType] of TAmmoTestProc = |
32 ( |
32 ( |
33 {amGrenade} nil,//TestGrenade, |
33 {amGrenade} @TestGrenade, |
34 {amClusterBomb} nil, |
34 {amClusterBomb} nil, |
35 {amBazooka} @TestBazooka, |
35 {amBazooka} @TestBazooka, |
36 {amUFO} nil, |
36 {amUFO} nil, |
37 {amShotgun} nil,//TestShotgun, |
37 {amShotgun} nil,//TestShotgun, |
38 {amPickHammer} nil, |
38 {amPickHammer} nil, |
114 end; |
114 end; |
115 end |
115 end |
116 until (rTime > 4500); |
116 until (rTime > 4500); |
117 TestBazooka:= Result |
117 TestBazooka:= Result |
118 end; |
118 end; |
119 { |
119 |
120 function TestGrenade(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
120 function TestGrenade(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
121 const tDelta = 24; |
121 const tDelta = 24; |
122 var Vx, Vy, r: hwFloat; |
122 var Vx, Vy, r: hwFloat; |
123 Score, EX, EY: LongInt; |
123 Score, EX, EY, Result: LongInt; |
124 TestTime: Longword; |
124 TestTime: Longword; |
125 |
125 |
126 function CheckTrace: LongInt; |
126 function CheckTrace: LongInt; |
127 var x, y, dY: hwFloat; |
127 var x, y, dY: hwFloat; |
128 t: LongInt; |
128 t: LongInt; |
129 begin |
129 begin |
130 x:= Me.X; |
130 x:= Me^.X; |
131 y:= Me.Y; |
131 y:= Me^.Y; |
132 dY:= -Vy; |
132 dY:= -Vy; |
133 t:= TestTime; |
133 t:= TestTime; |
134 repeat |
134 repeat |
135 x:= x + Vx; |
135 x:= x + Vx; |
136 y:= y + dY; |
136 y:= y + dY; |
137 dY:= dY + cGravity; |
137 dY:= dY + cGravity; |
138 dec(t) |
138 dec(t) |
139 until TestColl(round(x), round(y), 5) or (t = 0); |
139 until TestColl(hwRound(x), hwRound(y), 5) or (t = 0); |
140 EX:= round(x); |
140 EX:= hwRound(x); |
141 EY:= round(y); |
141 EY:= hwRound(y); |
142 if t < 50 then Result:= RateExplosion(Me, round(x), round(y), 101) |
142 if t < 50 then CheckTrace:= RateExplosion(Me, EX, EY, 101) |
143 else Result:= Low(LongInt) |
143 else CheckTrace:= Low(LongInt) |
144 end; |
144 end; |
145 |
145 |
146 begin |
146 begin |
147 Result:= BadTurn; |
147 Result:= BadTurn; |
148 TestTime:= 0; |
148 TestTime:= 0; |
149 ExplR:= 0; |
149 ExplR:= 0; |
150 repeat |
150 repeat |
151 inc(TestTime, 1000); |
151 inc(TestTime, 1000); |
152 Vx:= (Targ.X - Me.X) / (TestTime + tDelta); |
152 Vx:= (Targ.X - Me^.X) / (TestTime + tDelta); |
153 Vy:= cGravity*((TestTime + tDelta) div 2) - (Targ.Y - Me.Y) / (TestTime + tDelta); |
153 Vy:= cGravity * ((TestTime + tDelta) div 2) - (Targ.Y - Me^.Y) / (TestTime + tDelta); |
154 r:= sqr(Vx) + sqr(Vy); |
154 r:= Distance(Vx, Vy); |
155 if r <= 1 then |
155 if not (r > 1) then |
156 begin |
156 begin |
157 Score:= CheckTrace; |
157 Score:= CheckTrace; |
158 if Result < Score then |
158 if Result < Score then |
159 begin |
159 begin |
160 r:= sqrt(r); |
160 Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random(Level)); |
161 Angle:= DxDy2AttackAngle(Vx, Vy) + rndSign(random(Level)); |
161 Power:= hwRound(r * cMaxPower) + AIrndSign(random(Level) * 12); |
162 Power:= round(r * cMaxPower) + rndSign(random(Level) * 12); |
|
163 Time:= TestTime; |
162 Time:= TestTime; |
164 ExplR:= 100; |
163 ExplR:= 100; |
165 ExplX:= EX; |
164 ExplX:= EX; |
166 ExplY:= EY; |
165 ExplY:= EY; |
167 Result:= Score |
166 Result:= Score |
168 end; |
167 end; |
169 end |
168 end |
170 until (TestTime = 5000) |
169 until (TestTime = 5000); |
171 end; |
170 TestGrenade:= Result |
172 |
171 end; |
|
172 { |
173 function TestShotgun(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
173 function TestShotgun(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt; |
174 var Vx, Vy, x, y: hwFloat; |
174 var Vx, Vy, x, y: hwFloat; |
175 begin |
175 begin |
176 ExplR:= 0; |
176 ExplR:= 0; |
177 if Metric(round(Me.X), round(Me.Y), Targ.X, Targ.Y) < 80 then |
177 if Metric(round(Me.X), round(Me.Y), Targ.X, Targ.Y) < 80 then |