hedgewars/uAIAmmoTests.pas
changeset 5151 cbadb9fa52fc
parent 5150 63ad8a648afd
child 5164 a2a67433633d
equal deleted inserted replaced
5150:63ad8a648afd 5151:cbadb9fa52fc
   119 begin
   119 begin
   120 Metric:= abs(x1 - x2) + abs(y1 - y2)
   120 Metric:= abs(x1 - x2) + abs(y1 - y2)
   121 end;
   121 end;
   122 
   122 
   123 function TestBazooka(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   123 function TestBazooka(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   124 var Vx, Vy, r: hwFloat;
   124 var Vx, Vy, r, mX, mY: real;
   125     rTime: LongInt;
   125     rTime: LongInt;
   126     Score, EX, EY: LongInt;
   126     Score, EX, EY: LongInt;
   127     valueResult: LongInt;
   127     valueResult: LongInt;
   128 
   128 
   129     function CheckTrace: LongInt;
   129     function CheckTrace: LongInt;
   130     var x, y, dX, dY: hwFloat;
   130     var x, y, dX, dY: real;
   131         t: LongInt;
   131         t: LongInt;
   132         value: LongInt;
   132         value: LongInt;
   133     begin
   133     begin
   134     x:= Me^.X;
   134     x:= mX;
   135     y:= Me^.Y;
   135     y:= mY;
   136     dX:= Vx;
   136     dX:= Vx;
   137     dY:= -Vy;
   137     dY:= -Vy;
   138     t:= rTime;
   138     t:= rTime;
   139     repeat
   139     repeat
   140       x:= x + dX;
   140       x:= x + dX;
   141       y:= y + dY;
   141       y:= y + dY;
   142       dX:= dX + cWindSpeed;
   142       dX:= dX + cWindSpeedf;
   143       dY:= dY + cGravity;
   143       dY:= dY + cGravityf;
   144       dec(t)
   144       dec(t)
   145     until TestCollExcludingMe(Me, hwRound(x), hwRound(y), 5) or (t <= 0);
   145     until TestCollExcludingMe(Me, trunc(x), trunc(y), 5) or (t <= 0);
   146     EX:= hwRound(x);
   146     EX:= trunc(x);
   147     EY:= hwRound(y);
   147     EY:= trunc(y);
   148     value:= RateExplosion(Me, EX, EY, 101);
   148     value:= RateExplosion(Me, EX, EY, 101);
   149     if value = 0 then value:= - Metric(Targ.X, Targ.Y, EX, EY) div 64;
   149     if value = 0 then value:= - Metric(Targ.X, Targ.Y, EX, EY) div 64;
   150     CheckTrace:= value;
   150     CheckTrace:= value;
   151     end;
   151     end;
   152 
   152 
   153 begin
   153 begin
       
   154 mX:= hwFloat2Float(Me^.X);
       
   155 mY:= hwFloat2Float(Me^.Y);
   154 ap.Time:= 0;
   156 ap.Time:= 0;
   155 rTime:= 350;
   157 rTime:= 350;
   156 ap.ExplR:= 0;
   158 ap.ExplR:= 0;
   157 valueResult:= BadTurn;
   159 valueResult:= BadTurn;
   158 repeat
   160 repeat
   159   rTime:= rTime + 300 + Level * 50 + random(300);
   161   rTime:= rTime + 300 + Level * 50 + random(300);
   160   Vx:= - cWindSpeed * rTime * _0_5 + (int2hwFloat(Targ.X + AIrndSign(2)) - Me^.X) / int2hwFloat(rTime);
   162   Vx:= - cWindSpeedf * rTime * 0.5 + (Targ.X + AIrndSign(2) - mX) / rTime;
   161   Vy:= cGravity * rTime * _0_5 - (int2hwFloat(Targ.Y) - Me^.Y) / int2hwFloat(rTime);
   163   Vy:= cGravityf * rTime * 0.5 - (Targ.Y - mY) / rTime;
   162   r:= Distance(Vx, Vy);
   164   r:= sqrt(sqr(Vx) + sqr(Vy));
   163   if not (r > _1) then
   165   if not (r > 1) then
   164      begin
   166      begin
   165      Score:= CheckTrace;
   167      Score:= CheckTrace;
   166      if valueResult <= Score then
   168      if valueResult <= Score then
   167         begin
   169         begin
   168         ap.Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random((Level - 1) * 9));
   170         ap.Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random((Level - 1) * 9));
   169         ap.Power:= hwRound(r * cMaxPower) - random((Level - 1) * 17 + 1);
   171         ap.Power:= trunc(r * cMaxPower) - random((Level - 1) * 17 + 1);
   170         ap.ExplR:= 100;
   172         ap.ExplR:= 100;
   171         ap.ExplX:= EX;
   173         ap.ExplX:= EX;
   172         ap.ExplY:= EY;
   174         ap.ExplY:= EY;
   173         valueResult:= Score
   175         valueResult:= Score
   174         end;
   176         end;