hedgewars/uAIAmmoTests.pas
changeset 439 c336ed82e76d
parent 438 04bcc3fb127a
child 498 9c8b385dc9a1
equal deleted inserted replaced
438:04bcc3fb127a 439:c336ed82e76d
    48 {amMineStrike}    nil,
    48 {amMineStrike}    nil,
    49 {amBlowTorch}     nil,
    49 {amBlowTorch}     nil,
    50 {amGirder}        nil
    50 {amGirder}        nil
    51                   );
    51                   );
    52 
    52 
    53 const BadTurn = Low(LongInt);
    53 const BadTurn = Low(LongInt) div 4;
    54 
    54 
    55 
    55 
    56 implementation
    56 implementation
    57 uses uMisc, uAIMisc, uLand;
    57 uses uMisc, uAIMisc, uLand;
    58 
    58 
   104   if not (r > 1) then
   104   if not (r > 1) then
   105      begin
   105      begin
   106      Score:= CheckTrace;
   106      Score:= CheckTrace;
   107      if Result <= Score then
   107      if Result <= Score then
   108         begin
   108         begin
   109         Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random((Level - 1) * 11));
   109         Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random((Level - 1) * 9));
   110         Power:= hwRound(r * cMaxPower) - random((Level - 1) * 17 + 1);
   110         Power:= hwRound(r * cMaxPower) - random((Level - 1) * 17 + 1);
   111         ExplR:= 100;
   111         ExplR:= 100;
   112         ExplX:= EX;
   112         ExplX:= EX;
   113         ExplY:= EY;
   113         ExplY:= EY;
   114         Result:= Score
   114         Result:= Score
   165         ExplX:= EX;
   165         ExplX:= EX;
   166         ExplY:= EY;
   166         ExplY:= EY;
   167         Result:= Score
   167         Result:= Score
   168         end;
   168         end;
   169      end
   169      end
   170 until (TestTime = 5000);
   170 until (TestTime = 4000);
   171 TestGrenade:= Result
   171 TestGrenade:= Result
   172 end;
   172 end;
   173 
   173 
   174 function TestShotgun(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
   174 function TestShotgun(Me: PGear; Targ: TPoint; Level: LongInt; var Time: Longword; var Angle, Power: LongInt; var ExplX, ExplY, ExplR: LongInt): LongInt;
   175 var Vx, Vy, x, y: hwFloat;
   175 var Vx, Vy, x, y: hwFloat;
   176     rx, ry, Result: LongInt;
   176     rx, ry, Result: LongInt;
   177 begin
   177 begin
   178 ExplR:= 0;
   178 ExplR:= 0;
       
   179 Time:= 0;
       
   180 Power:= 1;
   179 if Metric(hwRound(Me^.X), hwRound(Me^.Y), Targ.X, Targ.Y) < 80 then
   181 if Metric(hwRound(Me^.X), hwRound(Me^.Y), Targ.X, Targ.Y) < 80 then
   180    begin
   182    exit(BadTurn);
   181    Result:= BadTurn;
       
   182    exit
       
   183    end;
       
   184 Time:= 0;
       
   185 Power:= 1;
       
   186 Vx:= (Targ.X - Me^.X) * _1div1024;
   183 Vx:= (Targ.X - Me^.X) * _1div1024;
   187 Vy:= (Targ.Y - Me^.Y) * _1div1024;
   184 Vy:= (Targ.Y - Me^.Y) * _1div1024;
   188 x:= Me^.X;
   185 x:= Me^.X;
   189 y:= Me^.Y;
   186 y:= Me^.Y;
   190 Angle:= DxDy2AttackAngle(Vx, -Vy);
   187 Angle:= DxDy2AttackAngle(Vx, -Vy);
   208 var Vx, Vy, x, y, t: hwFloat;
   205 var Vx, Vy, x, y, t: hwFloat;
   209     d: Longword;
   206     d: Longword;
   210     Result: LongInt;
   207     Result: LongInt;
   211 begin
   208 begin
   212 ExplR:= 0;
   209 ExplR:= 0;
       
   210 Time:= 0;
       
   211 Power:= 1;
   213 if hwAbs(Me^.X - Targ.X) + hwAbs(Me^.Y - Targ.Y) < 80 then
   212 if hwAbs(Me^.X - Targ.X) + hwAbs(Me^.Y - Targ.Y) < 80 then
   214    begin
   213    exit(BadTurn);
   215    Result:= BadTurn;
       
   216    exit
       
   217    end;
       
   218 Time:= 0;
       
   219 Power:= 1;
       
   220 t:= _0_5 / Distance(Targ.X - Me^.X, Targ.Y - Me^.Y);
   214 t:= _0_5 / Distance(Targ.X - Me^.X, Targ.Y - Me^.Y);
   221 Vx:= (Targ.X - Me^.X) * t;
   215 Vx:= (Targ.X - Me^.X) * t;
   222 Vy:= (Targ.Y - Me^.Y) * t;
   216 Vy:= (Targ.Y - Me^.Y) * t;
   223 x:= Me^.X;
   217 x:= Me^.X;
   224 y:= Me^.Y;
   218 y:= Me^.Y;